libwreport
3.29
|
Binary buffer with bit-level read operations. More...
#include <input.h>
Public Member Functions | |
Input (const std::string &in) | |
Wrap a string iinto a Input. More... | |
void | scan_lead_sections () |
Scan the message filling in the sec[] array of start offsets of sections 0 and 1. More... | |
void | scan_other_sections (bool has_optional) |
Scan the message filling in the sec[] array of section start offsets of all sections from 2 on. More... | |
unsigned | offset () const |
Return the current decoding byte offset. | |
unsigned | bits_left () const |
Return the number of bits left in the message to be decoded. | |
unsigned | read_byte (unsigned pos) const |
Read a byte value at offset pos. | |
unsigned | read_byte (unsigned section, unsigned pos) const |
Read a byte value at offset pos inside section section. | |
unsigned | read_number (unsigned pos, unsigned byte_len) const |
Read a big endian integer value byte_len bytes long, at offset pos. | |
unsigned | read_number (unsigned section, unsigned pos, unsigned byte_len) const |
Read a big endian integer value byte_len bytes long, at offset pos inside section section. | |
uint32_t | get_bits (unsigned n) |
Get the integer value of the next 'n' bits from the decode input n must be <= 32. | |
void | debug_dump_next_bits (const char *desc, int count) const |
Dump to stderr 'count' bits of 'buf', starting at the 'ofs-th' bit. | |
void | parse_error (const char *fmt,...) const WREPORT_THROWF_ATTRS(2 |
Throw an error_parse at the current decoding location. | |
void void | parse_error (unsigned pos, const char *fmt,...) const WREPORT_THROWF_ATTRS(3 |
Throw an error_parse at the given decoding location. | |
void void void | parse_error (unsigned section, unsigned pos, const char *fmt,...) const WREPORT_THROWF_ATTRS(4 |
Throw an error_parse at the given decoding location inside the given section. | |
void void void void | check_available_data (unsigned pos, size_t datalen, const char *expected) |
Check that the input buffer contains at least datalen characters after offset pos; throw error_parse otherwise. More... | |
void | check_available_message_data (unsigned section, unsigned pos, size_t datalen, const char *expected) |
Check that the input buffer contains at least datalen characters after offset pos in section section; throw error_parse otherwise. More... | |
void | check_available_section_data (unsigned section, unsigned pos, size_t datalen, const char *expected) |
Check that the given section in the input buffer contains at least datalen characters after offset pos; throw error_parse otherwise. More... | |
void | decode_compressed_number (Var &dest, uint32_t base, unsigned diffbits) |
Decode a compressed number as described by dest.info(), ad set it as value for dest. More... | |
void | decode_number (Var &dest) |
Decode a number as described by dest.info(), and set it as value for dest. More... | |
bool | decode_compressed_base (Varinfo info, uint32_t &base, uint32_t &diffbits) |
void | decode_compressed_number (Varinfo info, unsigned subsets, std::function< void(unsigned, Var &&)> dest) |
Decode a number as described by info from a compressed bufr with subsets subsets, and send the resulting variables to dest. | |
void | decode_string (Varinfo info, unsigned subsets, DispatchToSubsets &dest) |
void | decode_compressed_number (Varinfo info, unsigned subsets, DispatchToSubsets &dest) |
void | decode_compressed_number (Varinfo info, const bulletin::AssociatedField &afield, unsigned subsets, std::function< void(unsigned, Var &&)> dest) |
Decode a number as described by info from a compressed bufr with subsets subsets, and send the resulting variables to dest. | |
void | decode_compressed_semantic_number (Var &dest, unsigned subsets) |
Decode a number as described by dest.info(), and set it as value for dest. More... | |
bool | decode_string (unsigned bit_len, char *str, size_t &len) |
Read a string from the data section. More... | |
void | decode_string (Var &dest) |
Decode a string as described by dest.info(), ad set it as value for dest. More... | |
void | decode_string (Var &dest, unsigned subsets) |
Decode a string as described by dest.info(), and set it as value for dest. More... | |
void | decode_string (Varinfo info, unsigned subsets, std::function< void(unsigned, Var &&)> dest) |
Decode a string as described by info from a compressed bufr with subsets subsets, and send the resulting variables to dest. | |
void | decode_binary (Var &dest) |
Decode a generic binary value as-is, as described by dest.info(), ad set it as value for dest. More... | |
std::string | decode_uncompressed_bitmap (unsigned size) |
Decode an uncompressed bitmap of size bits. More... | |
std::string | decode_compressed_bitmap (unsigned size) |
Decode a "compressed" bitmap of size bits. More... | |
Data Fields | |
const uint8_t * | data |
Input buffer. | |
size_t | data_len |
Input buffer size. | |
const char * | fname = nullptr |
Input file name (optional). More... | |
size_t | start_offset = 0 |
File offset of the start of the message. More... | |
unsigned | s4_cursor = 0 |
Offset of the byte we are currently decoding. | |
uint8_t | pbyte = 0 |
Byte we are currently decoding. | |
int | pbyte_len = 0 |
Bits left in pbyte to decode. | |
unsigned | sec [6] |
Offsets of the start of BUFR sections. | |
Protected Member Functions | |
void | scan_section_length (unsigned sec_no) |
Scan length of section sec_no, filling in the start of the next section in sec[sec_no + 1]. | |
Binary buffer with bit-level read operations.
wreport::bufr::Input::Input | ( | const std::string & | in | ) |
Wrap a string iinto a Input.
in | String with the data to read |
void void void void wreport::bufr::Input::check_available_data | ( | unsigned | pos, |
size_t | datalen, | ||
const char * | expected | ||
) |
Check that the input buffer contains at least datalen characters after offset pos; throw error_parse otherwise.
pos | Starting offset of the required data |
datalen | Required amount of data expected starting from pos |
expected | name of what we are about to decode, used for generating nice error messages |
void wreport::bufr::Input::check_available_message_data | ( | unsigned | section, |
unsigned | pos, | ||
size_t | datalen, | ||
const char * | expected | ||
) |
Check that the input buffer contains at least datalen characters after offset pos in section section; throw error_parse otherwise.
section | Number of the section to check |
pos | Starting offset inside the section of the required data |
datalen | Required amount of data expected starting from pos |
expected | Name of what we are about to decode, used for generating nice error messages |
void wreport::bufr::Input::check_available_section_data | ( | unsigned | section, |
unsigned | pos, | ||
size_t | datalen, | ||
const char * | expected | ||
) |
Check that the given section in the input buffer contains at least datalen characters after offset pos; throw error_parse otherwise.
section | Number of the section to check |
pos | Starting offset inside the section of the required data |
datalen | Required amount of data expected starting from pos |
expected | Name of what we are about to decode, used for generating nice error messages |
void wreport::bufr::Input::decode_binary | ( | Var & | dest | ) |
Decode a generic binary value as-is, as described by dest.info(), ad set it as value for dest.
It is assumed that dest is not set, therefore in case we decode a missing value, dest will not be touched.
dest | Variable which holds the decoding information and that will hold the decoded value |
std::string wreport::bufr::Input::decode_compressed_bitmap | ( | unsigned | size | ) |
Decode a "compressed" bitmap of size bits.
The result will be a string size bytes long, with a '+' where the bitmap reports that data is present, and a '-' where the bitmap reports that data is not present.
It would be more correct to say that it decodes a bitmap from a compressed BUFR message, because bitmaps in compressed messages are actually encoded with 7 bits per bit instead of one, because after each bit they need to send 6 bits saying that it will be followed by 0 bits of difference values.
void wreport::bufr::Input::decode_compressed_number | ( | Var & | dest, |
uint32_t | base, | ||
unsigned | diffbits | ||
) |
Decode a compressed number as described by dest.info(), ad set it as value for dest.
dest | Variable which holds the decoding information and that will hold the decoded value |
base | The base value for the compressed number |
diffbits | The number of bits used to encode the difference from base |
void wreport::bufr::Input::decode_compressed_semantic_number | ( | Var & | dest, |
unsigned | subsets | ||
) |
Decode a number as described by dest.info(), and set it as value for dest.
The number is decoded for subsets compressed datasets, and an exception is thrown if the values differ.
dest | Variable which holds the decoding information and that will hold the decoded value |
subsets | Number of subsets in the compressed data section |
void wreport::bufr::Input::decode_number | ( | Var & | dest | ) |
Decode a number as described by dest.info(), and set it as value for dest.
dest | Variable which holds the decoding information and that will hold the decoded value |
bool wreport::bufr::Input::decode_string | ( | unsigned | bit_len, |
char * | str, | ||
size_t & | len | ||
) |
Read a string from the data section.
bit_len | Number of bits (not bytes) to read. It is normally a multiple of 8, and when it is not, the last character will contain the partial byte read. |
str | Buffer where the string is written. Must be big enough to contain the longest string described by info, plus 2 bytes |
len | The string length |
void wreport::bufr::Input::decode_string | ( | Var & | dest | ) |
Decode a string as described by dest.info(), ad set it as value for dest.
It is assumed that dest is not set, therefore in case we decode a missing value, dest will not be touched.
dest | Variable which holds the decoding information and that will hold the decoded value |
void wreport::bufr::Input::decode_string | ( | Var & | dest, |
unsigned | subsets | ||
) |
Decode a string as described by dest.info(), and set it as value for dest.
The string is decoded for subsets compressed datasets, and an exception is thrown if the values differ.
dest | Variable which holds the decoding information and that will hold the decoded value |
subsets | Number of subsets in the compressed data section |
std::string wreport::bufr::Input::decode_uncompressed_bitmap | ( | unsigned | size | ) |
Decode an uncompressed bitmap of size bits.
The result will be a string size bytes long, with a '+' where the bitmap reports that data is present, and a '-' where the bitmap reports that data is not present.
void wreport::bufr::Input::scan_lead_sections | ( | ) |
Scan the message filling in the sec[] array of start offsets of sections 0 and 1.
We cannot scan past section 1 until we decode it, because we need to know if section 2 is present or not
void wreport::bufr::Input::scan_other_sections | ( | bool | has_optional | ) |
Scan the message filling in the sec[] array of section start offsets of all sections from 2 on.
It also initialises points s4_cursor to the begin of the data in section 4.
has_optional | True if the optional section is present, false if it should be skipped. |
const char* wreport::bufr::Input::fname = nullptr |
Input file name (optional).
If available, it will be used to generate better error messages.
If not available, it is NULL.
size_t wreport::bufr::Input::start_offset = 0 |
File offset of the start of the message.
If available, it will be used to generate better error messages.
If not available, it is 0.