wreport::bufr::Input Class Reference

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.
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.
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 | skip_bits (unsigned n)
| Skip the next n bits.
void | debug_dump_next_bits (const char *desc, unsigned count, const std::vector< unsigned > &groups={}) const
| Dump to stderr 'count' bits of 'buf', starting at the 'ofs-th' bit.
void | debug_find_sequence (const char *pattern) const
| Match the given pattern as regexp on the still unread input bitstream, with bits converted to a string of '0' and '1'.
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_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.
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.
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.
void | decode_number (Var &dest)
| Decode a number as described by dest.info(), and set it as value for dest.
bool | decode_compressed_base (Varinfo info, uint32_t &base, uint32_t &diffbits)
| Decode the base value for a variable in a compressed BUFR.
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_af (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.
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, 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.
std::string | decode_uncompressed_bitmap (unsigned size)
| Decode an uncompressed bitmap of size bits.
std::string | decode_compressed_bitmap (unsigned size)
| Decode a "compressed" bitmap of size bits.

## Data Fields

const uint8_t * | data
| Input buffer.
size_t | data_len
| Input buffer size.
const char * | fname = nullptr
| Input file name (optional).
size_t | start_offset = 0
| File offset of the start of the message.
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].

## Detailed Description

Binary buffer with bit-level read operations.

## Constructor & Destructor Documentation

## Input()

wreport::bufr::Input::Input | ( | const std::string & | in | ) |

Wrap a string iinto a Input.

Parameters

  in | String with the data to read

## Member Function Documentation

## check_available_data()

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.

Parameters

  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

References check_available_data().

Referenced by check_available_data().

## check_available_message_data()

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.

Parameters

  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

References check_available_message_data().

Referenced by check_available_message_data().

## check_available_section_data()

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.

Parameters

  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

References check_available_section_data().

Referenced by check_available_section_data().

## decode_binary()

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.

Parameters

  dest | Variable which holds the decoding information and that will hold the decoded value

References decode_binary().

Referenced by decode_binary().

## decode_compressed_bitmap()

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.

References decode_compressed_bitmap().

Referenced by decode_compressed_bitmap().

## decode_compressed_number()

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.

Parameters

  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

References decode_compressed_number().

Referenced by decode_compressed_number(), and decode_compressed_number().

## decode_compressed_semantic_number()

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.

Parameters

  dest | Variable which holds the decoding information and that will hold the decoded value
  subsets | Number of subsets in the compressed data section

References decode_compressed_semantic_number().

Referenced by decode_compressed_semantic_number().

## decode_number()

void wreport::bufr::Input::decode_number | ( | Var & | dest | ) |

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

Parameters

  dest | Variable which holds the decoding information and that will hold the decoded value

References decode_number().

Referenced by decode_number().

## decode_string() [1/3]

bool wreport::bufr::Input::decode_string | ( | unsigned | bit_len,
|  | char * | str,
|  | size_t & | len )

Read a string from the data section.

Parameters

  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.

Return values

  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

Returns
  true if we decoded a real string, false if we decoded a missing string value

## decode_string() [2/3]

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.

Parameters

  dest | Variable which holds the decoding information and that will hold the decoded value

## decode_string() [3/3]

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.

Parameters

  dest | Variable which holds the decoding information and that will hold the decoded value
  subsets | Number of subsets in the compressed data section

## decode_uncompressed_bitmap()

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.

References decode_uncompressed_bitmap().

Referenced by decode_uncompressed_bitmap().

## scan_lead_sections()

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

## scan_other_sections()

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.

Parameters

  has_optional | True if the optional section is present, false if it should be skipped.

## Field Documentation

## fname

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.

## start_offset

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.

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

- input.h