libwreport  3.12
bulletin.h
1 #ifndef WREPORT_BULLETIN_H
2 #define WREPORT_BULLETIN_H
3 
4 #include <wreport/var.h>
5 #include <wreport/subset.h>
6 #include <wreport/opcodes.h>
7 #include <wreport/tables.h>
8 #include <vector>
9 #include <memory>
10 
11 namespace wreport {
12 struct DTable;
13 
29 struct Bulletin
30 {
38  std::string fname;
39 
47  off_t offset = 0;
48 
59  uint8_t master_table_number = 0;
60 
62  uint8_t data_category = 0xff;
63 
65  uint8_t data_subcategory = 0xff;
66 
81  uint8_t data_subcategory_local = 0xff;
82 
87  uint16_t originating_centre = 0xffff;
88 
93  uint16_t originating_subcentre = 0xffff;
94 
100 
108  uint16_t rep_year = 0;
109  uint8_t rep_month = 0;
110  uint8_t rep_day = 0;
111  uint8_t rep_hour = 0;
112  uint8_t rep_minute = 0;
113  uint8_t rep_second = 0;
116  Tables tables;
118 
120  std::vector<Varcode> datadesc;
121 
123  std::vector<Subset> subsets;
124 
125 
126  Bulletin();
127  virtual ~Bulletin();
128 
130  virtual void clear();
131 
133  virtual const char* encoding_name() const throw () = 0;
134 
144  Subset& obtain_subset(unsigned subsection);
145 
154  const Subset& subset(unsigned subsection) const;
155 
157  virtual void load_tables() = 0;
158 
160  virtual std::string encode() const = 0;
161 
163  void print(FILE* out) const;
164 
166  void print_structured(FILE* out) const;
167 
169  virtual void print_details(FILE* out) const;
170 
179  void print_datadesc(FILE* out, unsigned indent=0) const;
180 
192  virtual unsigned diff(const Bulletin& msg) const;
193 
195  virtual unsigned diff_details(const Bulletin& msg) const;
196 };
197 
198 
201 {
211  bool decode_adds_undef_attrs = false;
212 
220  static std::unique_ptr<BufrCodecOptions> create();
221 
222 protected:
223  BufrCodecOptions();
224 };
225 
226 
228 struct BufrBulletin : public Bulletin
229 {
231  uint8_t edition_number = 4;
232 
240  uint8_t master_table_version_number = 19;
241 
250  uint8_t master_table_version_number_local = 0;
251 
254 
260  std::string optional_section;
261 
267  unsigned section_end[6] = { 0, 0, 0, 0, 0, 0 };
268 
269 
270  virtual ~BufrBulletin();
271 
272  void clear();
273  const char* encoding_name() const throw () override { return "BUFR"; }
274  void load_tables() override;
275  std::string encode() const override;
276  void print_details(FILE* out) const override;
277  unsigned diff_details(const Bulletin& msg) const override;
278 
293  static bool read(FILE* in, std::string& buf, const char* fname=0, off_t* offset=0);
294 
305  static void write(const std::string& buf, FILE* out, const char* fname=0);
306 
311  static std::unique_ptr<BufrBulletin> create();
312 
325  static std::unique_ptr<BufrBulletin> decode_header(const std::string& raw, const char* fname="(memory)", size_t offset=0);
326 
341  static std::unique_ptr<BufrBulletin> decode_header(const std::string& raw, const BufrCodecOptions& opts, const char* fname="(memory)", size_t offset=0);
342 
355  static std::unique_ptr<BufrBulletin> decode(const std::string& raw, const char* fname="(memory)", size_t offset=0);
356 
371  static std::unique_ptr<BufrBulletin> decode_verbose(const std::string& raw, FILE* out, const char* fname="(memory)", size_t offset=0);
372 
387  static std::unique_ptr<BufrBulletin> decode(const std::string& raw, const BufrCodecOptions& opts, const char* fname="(memory)", size_t offset=0);
388 
389 protected:
390  BufrBulletin();
391 };
392 
393 
395 struct CrexBulletin : public Bulletin
396 {
398  uint8_t edition_number = 2;
399 
406  uint8_t master_table_version_number = 19;
407 
419  uint8_t master_table_version_number_bufr = 19;
420 
429  uint8_t master_table_version_number_local = 0;
430 
432  bool has_check_digit = false;
433 
434 
435  void clear();
436  const char* encoding_name() const throw () override { return "CREX"; }
437  void load_tables() override;
438  std::string encode() const override;
439  void print_details(FILE* out) const override;
440  unsigned diff_details(const Bulletin& msg) const override;
441 
456  static bool read(FILE* in, std::string& buf, const char* fname=0, off_t* offset=0);
457 
468  static void write(const std::string& buf, FILE* out, const char* fname=0);
469 
474  static std::unique_ptr<CrexBulletin> create();
475 
488  static std::unique_ptr<CrexBulletin> decode_header(const std::string& raw, const char* fname="(memory)", size_t offset=0);
489 
502  static std::unique_ptr<CrexBulletin> decode(const std::string& raw, const char* fname="(memory)", size_t offset=0);
503 
518  static std::unique_ptr<CrexBulletin> decode_verbose(const std::string& raw, FILE* out, const char* fname="(memory)", size_t offset=0);
519 
520 protected:
521  CrexBulletin();
522 };
523 
524 
534 namespace bulletin {
535 }
536 
537 }
538 #endif
uint16_t originating_subcentre
Identification of originating/generating sub-centre (allocated by originating/generating centre - see...
Definition: bulletin.h:93
uint8_t data_category
Data category (BUFR or CREX Table A)
Definition: bulletin.h:62
void print_structured(FILE *out) const
Dump the contents of this bulletin, in a more structured way.
uint8_t update_sequence_number
Update sequence number (zero for original messages and for messages containing only delayed reports; ...
Definition: bulletin.h:99
Tables tables
Varcode and opcode tables used for encoding or decoding.
Definition: bulletin.h:117
Options used to configure BUFR decoding.
Definition: bulletin.h:200
virtual unsigned diff(const Bulletin &msg) const
Compute the differences between two bulletins.
std::string optional_section
Raw optional section of the message.
Definition: bulletin.h:260
void print_datadesc(FILE *out, unsigned indent=0) const
Pretty-print the data descriptor section.
uint8_t rep_hour
Most typical time for the BUFR message contents.
Definition: bulletin.h:111
void print(FILE *out) const
Dump the contents of this bulletin.
std::vector< Subset > subsets
Decoded variables.
Definition: bulletin.h:123
STL namespace.
uint8_t master_table_number
BUFR Master table number.
Definition: bulletin.h:59
uint8_t data_subcategory
International data sub-category (see Common Code table C-13)
Definition: bulletin.h:65
const char * encoding_name() const override
Type of source/target encoding.
Definition: bulletin.h:273
virtual void load_tables()=0
Load a new set of tables to use for encoding this message.
virtual void clear()
Reset the bulletin.
Collection of BUFR/CREX tables used to work on a bulletin.
Definition: tables.h:17
virtual std::string encode() const =0
Encode the message.
Storage for the decoded data of a BUFR or CREX message.
Definition: bulletin.h:29
uint8_t rep_month
Most typical time for the BUFR message contents.
Definition: bulletin.h:109
const Subset & subset(unsigned subsection) const
Get a Subset from the message.
uint8_t data_subcategory_local
Local data sub-category, defined locally by automatic data-processing (ADP) centres.
Definition: bulletin.h:81
uint16_t rep_year
Most typical time for the BUFR message contents.
Definition: bulletin.h:108
uint16_t originating_centre
Identification of originating/generating centre (see Common Code table C-11)
Definition: bulletin.h:87
virtual void print_details(FILE *out) const
Print format-specific details.
CREX bulletin implementation.
Definition: bulletin.h:395
String functions.
Definition: benchmark.h:13
off_t offset
File offset of the start of the message.
Definition: bulletin.h:47
uint8_t rep_second
Most typical time for the BUFR message contents.
Definition: bulletin.h:113
uint8_t rep_minute
Most typical time for the BUFR message contents.
Definition: bulletin.h:112
virtual unsigned diff_details(const Bulletin &msg) const
Diff format-specific details.
bool compression
Whether the message is compressed.
Definition: bulletin.h:253
const char * encoding_name() const override
Type of source/target encoding.
Definition: bulletin.h:436
uint8_t rep_day
Most typical time for the BUFR message contents.
Definition: bulletin.h:110
Represent a BUFR/CREX data subset as a list of decoded variables.
Definition: subset.h:13
std::string fname
Input file name (optional).
Definition: bulletin.h:38
Subset & obtain_subset(unsigned subsection)
Get a Subset from the message.
BUFR bulletin implementation.
Definition: bulletin.h:228
std::vector< Varcode > datadesc
Parsed data descriptor section.
Definition: bulletin.h:120
virtual const char * encoding_name() const =0
Type of source/target encoding.