libwreport
2.4
|
Binary buffer with bit-level read operations. More...
#include <buffers.h>
Public Member Functions | |
BufrInput (const std::string &in) | |
Wrap a string iinto a BufrInput. | |
void | reset (const std::string &in) |
Start decoding a different buffer. | |
void | scan_lead_sections () |
Scan the message filling in the sec[] array of start offsets of sections 0 and 1. | |
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. | |
int | offset () const |
Return the current decoding byte offset. | |
int | 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 (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. | |
void | check_available_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. | |
void | decode_number (Var &dest, uint32_t base, unsigned diffbits) |
Decode a compressed number as described by dest.info(), ad set it as value for dest. | |
void | decode_number (Var &dest) |
Decode a number as described by dest.info(), and set it as value for dest. | |
void | decode_number (Varinfo info, unsigned subsets, CompressedVarSink &dest) |
Decode a number as described by info from a compressed bufr with subsets subsets, and send the resulting variables to dest. | |
void | decode_number (Var &dest, unsigned subsets) |
Decode a number as described by dest.info(), and set it as value for dest. | |
bool | decode_string (unsigned bit_len, char *str, size_t &len) |
Read a string from the data section. | |
void | decode_string (Var &dest) |
Decode a string as described by dest.info(), ad set it as value for dest. | |
void | decode_string (Var &dest, unsigned subsets) |
Decode a string as described by dest.info(), and set it as value for dest. | |
void | decode_string (Varinfo info, unsigned subsets, CompressedVarSink &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. | |
Data Fields | |
const unsigned char * | data |
Input buffer. | |
size_t | data_len |
Input buffer size. | |
const char * | fname |
Input file name (optional). | |
size_t | start_offset |
File offset of the start of the message. | |
unsigned | s4_cursor |
Offset of the byte we are currently decoding. | |
unsigned char | pbyte |
Byte we are currently decoding. | |
int | pbyte_len |
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::bulletin::BufrInput::BufrInput | ( | const std::string & | in | ) |
Wrap a string iinto a BufrInput.
in | String with the data to read |
void void void void wreport::bulletin::BufrInput::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::bulletin::BufrInput::check_available_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::bulletin::BufrInput::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 |
void wreport::bulletin::BufrInput::decode_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::bulletin::BufrInput::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 |
void wreport::bulletin::BufrInput::decode_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 |
bool wreport::bulletin::BufrInput::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::bulletin::BufrInput::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::bulletin::BufrInput::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 |
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::bulletin::BufrInput::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::bulletin::BufrInput::fname |
Input file name (optional).
If available, it will be used to generate better error messages.
If not available, it is NULL.
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.