libwreport  2.4
Public Member Functions | Data Fields | Protected Member Functions
wreport::bulletin::BufrInput Class Reference

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].

Detailed Description

Binary buffer with bit-level read operations.


Constructor & Destructor Documentation

wreport::bulletin::BufrInput::BufrInput ( const std::string &  in)

Wrap a string iinto a BufrInput.

Parameters:
inString with the data to read

Member Function Documentation

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.

Parameters:
posStarting offset of the required data
datalenRequired amount of data expected starting from pos
expectedname 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.

Parameters:
sectionNumber of the section to check
posStarting offset inside the section of the required data
datalenRequired amount of data expected starting from pos
expectedName of what we are about to decode, used for generating nice error messages

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.

Parameters:
destVariable 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.

Parameters:
destVariable which holds the decoding information and that will hold the decoded value
baseThe base value for the compressed number
diffbitsThe number of bits used to encode the difference from base

Decode a number as described by dest.info(), and set it as value for dest.

Parameters:
destVariable 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.

Parameters:
destVariable which holds the decoding information and that will hold the decoded value
subsetsNumber 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.

Parameters:
bit_lenNumber 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.
Return values:
strBuffer where the string is written. Must be big enough to contain the longest string described by info, plus 2 bytes
lenThe string length
Returns:
true if we decoded a real string, false if we decoded a missing string value

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.

Parameters:
destVariable 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.

Parameters:
destVariable which holds the decoding information and that will hold the decoded value
subsetsNumber 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

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.

Parameters:
has_optionalTrue if the optional section is present, false if it should be skipped.

Field Documentation

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.


The documentation for this class was generated from the following file: