/usr/include/wreport/bulletin.h is in libwreport-dev 3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | #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 <vector>
#include <memory>
namespace wreport {
struct DTable;
/**
* Storage for the decoded data of a BUFR or CREX message.
*
* A Bulletin roughly reflects the structure of a BUFR or CREX message: it
* contains metadata, a sequence of wreport::Varcode with the contents of a
* Data Descriptor Section, and one or more wreport::Subset with the decoded
* values.
*
* Subsets are essentially sequences of wreport::Var objects, and therefore
* contain the values together with the full range of variable information,
* including type, measurement units and number of significant digits.
*
* Extra values like quality control statistics or replaced values are
* represented as 'attributes' to the wreport::Var objects.
*/
struct Bulletin
{
/**
* Input file name (optional).
*
* If available, it will be used to generate better error messages.
*
* If not available, it is empty.
*/
std::string fname;
/**
* 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.
*/
off_t offset = 0;
/**
* BUFR Master table number.
*
* A master table may be defined for a scientific discipline other than meteorology.
* The current list of master tables, along with their associated values in
* octet 4, is as follows:
*
* \l 0: Meteorology maintained by the World Meteorological Organization (WMO)
* \l 10: Oceanography maintained by the Intergovernmental Oceanographic Commission (IOC) of UNESCO
*/
uint8_t master_table_number = 0;
/// Data category (BUFR or CREX Table A)
uint8_t data_category = 0xff;
/// International data sub-category (see Common Code table C-13)
uint8_t data_subcategory = 0xff;
/**
* Local data sub-category, defined locally by automatic data-processing
* (ADP) centres.
*
* Note: the local data sub-category is maintained for backwards
* compatibility with BUFR editions 0-3, since many ADP centres have made
* extensive use of such values in the past. The international data
* sub-category introduced with BUFR edition 4 is intended to provide a
* mechanism for better understanding of the overall nature and intent of
* messages exchanged between ADP centres. These two values (i.e. local
* sub-category and international sub-category) are intended to be
* supplementary to one another, so both may be used within a particular
* BUFR message.
*/
uint8_t data_subcategory_local = 0xff;
/**
* Identification of originating/generating centre (see Common Code table
* C-11)
*/
uint16_t originating_centre = 0xffff;
/**
* Identification of originating/generating sub-centre (allocated by
* originating/generating centre - see Common Code table C-12)
*/
uint16_t originating_subcentre = 0xffff;
/**
* Update sequence number (zero for original messages and for messages
* containing only delayed reports; incremented for the other updates)
*/
uint8_t update_sequence_number = 0;
/**
* Most typical time for the BUFR message contents.
*
* When accuracy of the time does not define a time unit, then the value
* for this unit shall be set to zero (e.g. for a SYNOP observation at 09
* UTC, minute = 0, second = 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;
/** @} */
/// Varcode and opcode tables used for encoding or decoding
Tables tables;
/// Parsed data descriptor section
std::vector<Varcode> datadesc;
/// Decoded variables
std::vector<Subset> subsets;
Bulletin();
virtual ~Bulletin();
/// Reset the bulletin
virtual void clear();
/// Type of source/target encoding
virtual const char* encoding_name() const throw () = 0;
/**
* Get a Subset from the message.
*
* The subset will be created if it does not exist, and it will be
* memory managed by the Bulletin.
*
* @param subsection
* The subsection index (starting from 0)
*/
Subset& obtain_subset(unsigned subsection);
/**
* Get a Subset from the message.
*
* An exception will be thrown if the subset does not exist
*
* @param subsection
* The subsection index (starting from 0)
*/
const Subset& subset(unsigned subsection) const;
/// Load a new set of tables to use for encoding this message
virtual void load_tables() = 0;
/// Encode the message
virtual std::string encode() const = 0;
/// Dump the contents of this bulletin
void print(FILE* out) const;
/// Dump the contents of this bulletin, in a more structured way
void print_structured(FILE* out) const;
/// Print format-specific details
virtual void print_details(FILE* out) const;
/**
* Pretty-print the data descriptor section
*
* @param out
* Output stream to use
* @param indent
* Indent all output by this amount of spaces
*/
void print_datadesc(FILE* out, unsigned indent=0) const;
/**
* Compute the differences between two bulletins
*
* Details of the differences found will be formatted using the notes
* system (@see notes.h).
*
* @param msg
* The bulletin to compare with this one
* @returns
* The number of differences found
*/
virtual unsigned diff(const Bulletin& msg) const;
/// Diff format-specific details
virtual unsigned diff_details(const Bulletin& msg) const;
};
/// Options used to configure BUFR decoding
struct BufrCodecOptions
{
/**
* By default (false) undefined attributes are not added to variables, and
* there is no difference between an undefined or a missing attribute.
*
* If this is set to true, undefined attributes are added to variables, so
* that it is possible to tell between a variable with no attributes and a
* variable for which the bulletin provides attributes but they have an
* missing value.
*/
bool decode_adds_undef_attrs = false;
/**
* Create a BufrCodecOptions
*
* Options may be added at any time to future versions of the structure. To
* reduce the likelyhook of breaking ABI, construction on stack is discouraged
* in favour of an allocator function.
*/
static std::unique_ptr<BufrCodecOptions> create();
protected:
BufrCodecOptions();
};
/// BUFR bulletin implementation
struct BufrBulletin : public Bulletin
{
/// BUFR edition number
uint8_t edition_number = 4;
/**
* Version number of BUFR master table used.
*
* See WMO Manual on Codes, Binary codes, FM94-XIV BUFR, Section 1
* Identification section, note 5, or FB95-XIV CREX, Specification of
* sections, note 3, for a list.
*/
uint8_t master_table_version_number = 19;
/**
* Version number of local table used to augment the master table.
*
* Local tables shall define those parts of the master table which are
* reserved for local use, thus version numbers of local tables may be
* changed at will by the originating centre. If no local table is used,
* the version number of the local table shall be encoded as 0.
*/
uint8_t master_table_version_number_local = 0;
/// Whether the message is compressed
bool compression;
/**
* Raw optional section of the message.
*
* It is empty if the message does not contain an optional section.
*/
std::string optional_section;
/**
* Offsets of the end of BUFR sections.
*
* This is only filled in during decoding.
*/
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;
/**
* Read an encoded BUFR message from a stream
*
* @param in
* The stream to read from
* @param buf
* The buffer where the data will be written
* @param fname
* File name to use in error messages
* @retval offset
* The offset in the file of the beginning of the BUFR data
* @returns
* true if a message was found, false on EOF
*/
static bool read(FILE* in, std::string& buf, const char* fname=0, off_t* offset=0);
/**
* Write an encoded BUFR message to a stream
*
* @param buf
* The buffer with the data to write
* @param out
* The stream to write to
* @param fname
* File name to use in error messages
*/
static void write(const std::string& buf, FILE* out, const char* fname=0);
/**
* To prevent breaking ABI if new members are added to bulletins, direct
* construction is discouraged in favour of an allocator function
*/
static std::unique_ptr<BufrBulletin> create();
/**
* Parse only the header of an encoded BUFR message
*
* @param buf
* The buffer to decode
* @param fname
* The file name to use for error messages
* @param offset
* The offset inside the file of the start of the bulletin, used for
* error messages
* @returns The new bulletin with the decoded message
*/
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
*
* @param buf
* The buffer to decode
* @param opts
* Options used to customise encoding or decoding.
* @param fname
* The file name to use for error messages
* @param offset
* The offset inside the file of the start of the bulletin, used for
* error messages
* @returns The new bulletin with the decoded message
*/
static std::unique_ptr<BufrBulletin> decode_header(const std::string& raw, const BufrCodecOptions& opts, const char* fname="(memory)", size_t offset=0);
/**
* Parse an encoded BUFR message
*
* @param buf
* The buffer to decode
* @param fname
* The file name to use for error messages
* @param offset
* The offset inside the file of the start of the bulletin, used for
* error messages
* @returns The new bulletin with the decoded message
*/
static std::unique_ptr<BufrBulletin> decode(const std::string& raw, const char* fname="(memory)", size_t offset=0);
/**
* Parse an encoded BUFR message
*
* @param buf
* The buffer to decode
* @param opts
* Options used to customise encoding or decoding.
* @param fname
* The file name to use for error messages
* @param offset
* The offset inside the file of the start of the bulletin, used for
* error messages
* @returns The new bulletin with the decoded message
*/
static std::unique_ptr<BufrBulletin> decode(const std::string& raw, const BufrCodecOptions& opts, const char* fname="(memory)", size_t offset=0);
protected:
BufrBulletin();
};
/// CREX bulletin implementation
struct CrexBulletin : public Bulletin
{
/// CREX Edition number
uint8_t edition_number = 2;
/**
* CREX master table version number.
*
* See WMO Manual on Codes, FB95-XIV CREX, Specification of sections, note
* 3, for a list.
*/
uint8_t master_table_version_number = 19;
/**
* BUFR master table version number.
*
* See WMO Manual on Codes, Binary codes, FM94-XIV BUFR, Section 1
* Identification section, note 5, for a list.
*
* FIXME: I could not find any reference to why CREX edition 2 has a
* separate field for BUFR master table version number but not for BUFR
* master table version, or why it needs to reference BUFR master tables at
* all.
*/
uint8_t master_table_version_number_bufr = 19;
/**
* Version number of local table used to augment the master table.
*
* Local tables shall define those parts of the master table which are
* reserved for local use, thus version numbers of local tables may be
* changed at will by the originating centre. If no local table is used,
* the version number of the local table shall be encoded as 0.
*/
uint8_t master_table_version_number_local = 0;
/// True if the CREX message uses the check digit feature
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;
/**
* Read an encoded BUFR message from a stream
*
* @param in
* The stream to read from
* @param buf
* The buffer where the data will be written
* @param fname
* File name to use in error messages
* @retval offset
* The offset in the file of the beginning of the BUFR data
* @returns
* true if a message was found, false on EOF
*/
static bool read(FILE* in, std::string& buf, const char* fname=0, off_t* offset=0);
/**
* Write an encoded BUFR message to a stream
*
* @param buf
* The buffer with the data to write
* @param out
* The stream to write to
* @param fname
* File name to use in error messages
*/
static void write(const std::string& buf, FILE* out, const char* fname=0);
/**
* To prevent breaking ABI if new members are added to bulletins, direct
* construction is discouraged in favour of an allocator function
*/
static std::unique_ptr<CrexBulletin> create();
/**
* Parse only the header of an encoded BUFR message
*
* @param buf
* The buffer to decode
* @param fname
* The file name to use for error messages
* @param offset
* The offset inside the file of the start of the bulletin, used for
* error messages
* @returns The new bulletin with the decoded message
*/
static std::unique_ptr<CrexBulletin> decode_header(const std::string& raw, const char* fname="(memory)", size_t offset=0);
/**
* Parse an encoded BUFR message
*
* @param buf
* The buffer to decode
* @param fname
* The file name to use for error messages
* @param offset
* The offset inside the file of the start of the bulletin, used for
* error messages
* @returns The new bulletin with the decoded message
*/
static std::unique_ptr<CrexBulletin> decode(const std::string& raw, const char* fname="(memory)", size_t offset=0);
protected:
CrexBulletin();
};
/**
* The bulletin namespace contains bulletin implementation details, internals
* and utility functions.
*
* The API and ABI of members of the bulletin namespace are not guaranteed to
* be stable, and can change in minor version changes. No part of the stable
* API/ABI introduce dependencies on unstable wreport API/ABI elements in the
* code using it.
*/
namespace bulletin {
}
}
#endif
|