bulletin.h
#ifndef WREPORT_BULLETIN_H
#define WREPORT_BULLETIN_H
#include <wreport/var.h>
#include <wreport/subset.h>
#include <wreport/opcodes.h>
#include <wreport/tables.h>
#include <wreport/fwd.h>
#include <vector>
#include <memory>
namespace wreport {
class Bulletin
{
public:
std::string fname;
off_t offset = 0;
uint8_t master_table_number = 0;
uint8_t data_category = 0xff;
uint8_t data_subcategory = 0xff;
uint8_t data_subcategory_local = 0xff;
uint16_t originating_centre = 0xffff;
uint16_t originating_subcentre = 0xffff;
uint8_t update_sequence_number = 0;
uint16_t rep_year = 0;
uint8_t rep_month = 0;
uint8_t rep_day = 0;
uint8_t rep_hour = 0;
uint8_t rep_minute = 0;
uint8_t rep_second = 0;
Tables tables;
std::vector<Varcode> datadesc;
std::vector<Subset> subsets;
Bulletin();
virtual ~Bulletin();
virtual void clear();
virtual const char* encoding_name() const throw () = 0;
Subset& obtain_subset(unsigned subsection);
const Subset& subset(unsigned subsection) const;
virtual void load_tables() = 0;
virtual std::string encode() const = 0;
void print(FILE* out) const;
void print_structured(FILE* out) const;
virtual void print_details(FILE* out) const;
void print_datadesc(FILE* out, unsigned indent=0) const;
virtual unsigned diff(const Bulletin& msg) const;
virtual unsigned diff_details(const Bulletin& msg) const;
};
class BufrCodecOptions
{
public:
bool decode_adds_undef_attrs = false;
static std::unique_ptr<BufrCodecOptions> create();
protected:
BufrCodecOptions();
};
class BufrBulletin : public Bulletin
{
public:
uint8_t edition_number = 4;
uint8_t master_table_version_number = 19;
uint8_t master_table_version_number_local = 0;
bool compression;
std::string optional_section;
unsigned section_end[6] = { 0, 0, 0, 0, 0, 0 };
virtual ~BufrBulletin();
void clear();
const char* encoding_name() const throw () override { return "BUFR"; }
void load_tables() override;
std::string encode() const override;
void print_details(FILE* out) const override;
unsigned diff_details(const Bulletin& msg) const override;
static bool read(FILE* in, std::string& buf, const char* fname=0, off_t* offset=0);
static void write(const std::string& buf, FILE* out, const char* fname=0);
static std::unique_ptr<BufrBulletin> create();
static std::unique_ptr<BufrBulletin> decode_header(const std::string& raw, const char* fname="(memory)", size_t offset=0);
static std::unique_ptr<BufrBulletin> decode_header(const std::string& raw, const BufrCodecOptions& opts, const char* fname="(memory)", size_t offset=0);
static std::unique_ptr<BufrBulletin> decode(const std::string& raw, const char* fname="(memory)", size_t offset=0);
static std::unique_ptr<BufrBulletin> decode_verbose(const std::string& raw, FILE* out, const char* fname="(memory)", size_t offset=0);
static std::unique_ptr<BufrBulletin> decode(const std::string& raw, const BufrCodecOptions& opts, const char* fname="(memory)", size_t offset=0);
protected:
BufrBulletin();
};
class CrexBulletin : public Bulletin
{
public:
uint8_t edition_number = 2;
uint8_t master_table_version_number = 19;
uint8_t master_table_version_number_bufr = 19;
uint8_t master_table_version_number_local = 0;
bool has_check_digit = false;
void clear();
const char* encoding_name() const throw () override { return "CREX"; }
void load_tables() override;
std::string encode() const override;
void print_details(FILE* out) const override;
unsigned diff_details(const Bulletin& msg) const override;
static bool read(FILE* in, std::string& buf, const char* fname=0, off_t* offset=0);
static void write(const std::string& buf, FILE* out, const char* fname=0);
static std::unique_ptr<CrexBulletin> create();
static std::unique_ptr<CrexBulletin> decode_header(const std::string& raw, const char* fname="(memory)", size_t offset=0);
static std::unique_ptr<CrexBulletin> decode(const std::string& raw, const char* fname="(memory)", size_t offset=0);
static std::unique_ptr<CrexBulletin> decode_verbose(const std::string& raw, FILE* out, const char* fname="(memory)", size_t offset=0);
protected:
CrexBulletin();
};
namespace bulletin {
}
}
#endif
wreport::BufrBulletin
BUFR bulletin implementation.
Definition bulletin.h:229
wreport::BufrBulletin::write
static void write(const std::string &buf, FILE *out, const char *fname=0)
Write an encoded BUFR message to a stream.
wreport::BufrBulletin::master_table_version_number
uint8_t master_table_version_number
Version number of BUFR master table used.
Definition bulletin.h:241
wreport::BufrBulletin::diff_details
unsigned diff_details(const Bulletin &msg) const override
Diff format-specific details.
wreport::BufrBulletin::master_table_version_number_local
uint8_t master_table_version_number_local
Version number of local table used to augment the master table.
Definition bulletin.h:251
wreport::BufrBulletin::read
static bool read(FILE *in, std::string &buf, const char *fname=0, off_t *offset=0)
Read an encoded BUFR message from a stream.
wreport::BufrBulletin::section_end
unsigned section_end[6]
Offsets of the end of BUFR sections.
Definition bulletin.h:268
wreport::BufrBulletin::clear
void clear()
Reset the bulletin.
wreport::BufrBulletin::create
static std::unique_ptr< BufrBulletin > create()
To prevent breaking ABI if new members are added to bulletins, direct construction is discouraged in ...
wreport::BufrBulletin::compression
bool compression
Whether the message is compressed.
Definition bulletin.h:254
wreport::BufrBulletin::encode
std::string encode() const override
Encode the message.
wreport::BufrBulletin::optional_section
std::string optional_section
Raw optional section of the message.
Definition bulletin.h:261
wreport::BufrBulletin::decode
static std::unique_ptr< BufrBulletin > decode(const std::string &raw, const char *fname="(memory)", size_t offset=0)
Parse an encoded BUFR message.
wreport::BufrBulletin::print_details
void print_details(FILE *out) const override
Print format-specific details.
wreport::BufrBulletin::decode_header
static std::unique_ptr< BufrBulletin > decode_header(const std::string &raw, const char *fname="(memory)", size_t offset=0)
Parse only the header of an encoded BUFR message.
wreport::BufrBulletin::load_tables
void load_tables() override
Load a new set of tables to use for encoding this message.
wreport::BufrBulletin::decode_verbose
static std::unique_ptr< BufrBulletin > decode_verbose(const std::string &raw, FILE *out, const char *fname="(memory)", size_t offset=0)
Parse an encoded BUFR message, printing decoding information.
wreport::BufrBulletin::encoding_name
const char * encoding_name() const override
Type of source/target encoding.
Definition bulletin.h:274
wreport::BufrBulletin::decode_header
static std::unique_ptr< BufrBulletin > decode_header(const std::string &raw, const BufrCodecOptions &opts, const char *fname="(memory)", size_t offset=0)
Parse only the header of an encoded BUFR message.
wreport::BufrBulletin::edition_number
uint8_t edition_number
BUFR edition number.
Definition bulletin.h:232
wreport::BufrBulletin::decode
static std::unique_ptr< BufrBulletin > decode(const std::string &raw, const BufrCodecOptions &opts, const char *fname="(memory)", size_t offset=0)
Parse an encoded BUFR message.
wreport::BufrCodecOptions
Options used to configure BUFR decoding.
Definition bulletin.h:200
wreport::BufrCodecOptions::create
static std::unique_ptr< BufrCodecOptions > create()
Create a BufrCodecOptions.
wreport::BufrCodecOptions::decode_adds_undef_attrs
bool decode_adds_undef_attrs
By default (false) undefined attributes are not added to variables, and there is no difference betwee...
Definition bulletin.h:211
wreport::Bulletin::print_details
virtual void print_details(FILE *out) const
Print format-specific details.
wreport::Bulletin::originating_centre
uint16_t originating_centre
Identification of originating/generating centre (see Common Code table C-11).
Definition bulletin.h:88
wreport::Bulletin::update_sequence_number
uint8_t update_sequence_number
Update sequence number (zero for original messages and for messages containing only delayed reports; ...
Definition bulletin.h:100
wreport::Bulletin::rep_hour
uint8_t rep_hour
Reference hour in bulletin header.
Definition bulletin.h:109
wreport::Bulletin::diff_details
virtual unsigned diff_details(const Bulletin &msg) const
Diff format-specific details.
wreport::Bulletin::subsets
std::vector< Subset > subsets
Decoded variables.
Definition bulletin.h:122
wreport::Bulletin::rep_minute
uint8_t rep_minute
Reference minute in bulletin header.
Definition bulletin.h:111
wreport::Bulletin::load_tables
virtual void load_tables()=0
Load a new set of tables to use for encoding this message.
wreport::Bulletin::originating_subcentre
uint16_t originating_subcentre
Identification of originating/generating sub-centre (allocated by originating/generating centre - see...
Definition bulletin.h:94
wreport::Bulletin::encoding_name
virtual const char * encoding_name() const =0
Type of source/target encoding.
wreport::Bulletin::rep_month
uint8_t rep_month
Reference month in bulletin header.
Definition bulletin.h:105
wreport::Bulletin::print_structured
void print_structured(FILE *out) const
Dump the contents of this bulletin, in a more structured way.
wreport::Bulletin::datadesc
std::vector< Varcode > datadesc
Parsed data descriptor section.
Definition bulletin.h:119
wreport::Bulletin::offset
off_t offset
File offset of the start of the message.
Definition bulletin.h:48
wreport::Bulletin::rep_year
uint16_t rep_year
Reference year in bulletin header.
Definition bulletin.h:103
wreport::Bulletin::tables
Tables tables
Varcode and opcode tables used for encoding or decoding.
Definition bulletin.h:116
wreport::Bulletin::fname
std::string fname
Input file name (optional).
Definition bulletin.h:39
wreport::Bulletin::rep_second
uint8_t rep_second
Reference second in bulletin header.
Definition bulletin.h:113
wreport::Bulletin::clear
virtual void clear()
Reset the bulletin.
wreport::Bulletin::encode
virtual std::string encode() const =0
Encode the message.
wreport::Bulletin::print_datadesc
void print_datadesc(FILE *out, unsigned indent=0) const
Pretty-print the data descriptor section.
wreport::Bulletin::obtain_subset
Subset & obtain_subset(unsigned subsection)
Get a Subset from the message.
wreport::Bulletin::print
void print(FILE *out) const
Dump the contents of this bulletin.
wreport::Bulletin::rep_day
uint8_t rep_day
Reference day in bulletin header.
Definition bulletin.h:107
wreport::Bulletin::subset
const Subset & subset(unsigned subsection) const
Get a Subset from the message.
wreport::Bulletin::diff
virtual unsigned diff(const Bulletin &msg) const
Compute the differences between two bulletins.
wreport::Bulletin::data_subcategory_local
uint8_t data_subcategory_local
Local data sub-category, defined locally by automatic data-processing (ADP) centres.
Definition bulletin.h:82
wreport::Bulletin::master_table_number
uint8_t master_table_number
BUFR Master table number.
Definition bulletin.h:60
wreport::Bulletin::data_category
uint8_t data_category
Data category (BUFR or CREX Table A).
Definition bulletin.h:63
wreport::Bulletin::data_subcategory
uint8_t data_subcategory
International data sub-category (see Common Code table C-13).
Definition bulletin.h:66
wreport::CrexBulletin::write
static void write(const std::string &buf, FILE *out, const char *fname=0)
Write an encoded BUFR message to a stream.
wreport::CrexBulletin::print_details
void print_details(FILE *out) const override
Print format-specific details.
wreport::CrexBulletin::decode_verbose
static std::unique_ptr< CrexBulletin > decode_verbose(const std::string &raw, FILE *out, const char *fname="(memory)", size_t offset=0)
Parse an encoded BUFR message, printing decoding information.
wreport::CrexBulletin::encode
std::string encode() const override
Encode the message.
wreport::CrexBulletin::read
static bool read(FILE *in, std::string &buf, const char *fname=0, off_t *offset=0)
Read an encoded BUFR message from a stream.
wreport::CrexBulletin::load_tables
void load_tables() override
Load a new set of tables to use for encoding this message.
wreport::CrexBulletin::diff_details
unsigned diff_details(const Bulletin &msg) const override
Diff format-specific details.
wreport::CrexBulletin::master_table_version_number_bufr
uint8_t master_table_version_number_bufr
BUFR master table version number.
Definition bulletin.h:421
wreport::CrexBulletin::has_check_digit
bool has_check_digit
True if the CREX message uses the check digit feature.
Definition bulletin.h:434
wreport::CrexBulletin::master_table_version_number
uint8_t master_table_version_number
CREX master table version number.
Definition bulletin.h:408
wreport::CrexBulletin::master_table_version_number_local
uint8_t master_table_version_number_local
Version number of local table used to augment the master table.
Definition bulletin.h:431
wreport::CrexBulletin::create
static std::unique_ptr< CrexBulletin > create()
To prevent breaking ABI if new members are added to bulletins, direct construction is discouraged in ...
wreport::CrexBulletin::encoding_name
const char * encoding_name() const override
Type of source/target encoding.
Definition bulletin.h:438
wreport::CrexBulletin::decode_header
static std::unique_ptr< CrexBulletin > decode_header(const std::string &raw, const char *fname="(memory)", size_t offset=0)
Parse only the header of an encoded BUFR message.
wreport::CrexBulletin::clear
void clear()
Reset the bulletin.
wreport::CrexBulletin::edition_number
uint8_t edition_number
CREX Edition number.
Definition bulletin.h:400
wreport::CrexBulletin::decode
static std::unique_ptr< CrexBulletin > decode(const std::string &raw, const char *fname="(memory)", size_t offset=0)
Parse an encoded BUFR message.
wreport::Subset
Represent a BUFR/CREX data subset as a list of decoded variables.
Definition subset.h:13
wreport::bulletin
The bulletin namespace contains bulletin implementation details, internals and utility functions.
Definition input.h:13
wreport
String functions.
Definition benchmark.h:13
wreport::Tables
Collection of BUFR/CREX tables used to work on a bulletin.
Definition tables.h:15