libwreport 3.40
decoder.h
1#ifndef WREPORT_BUFR_DECODER_H
2#define WREPORT_BUFR_DECODER_H
3
4#include <wreport/bufr/input.h>
5#include <wreport/bulletin.h>
6#include <wreport/bulletin/interpreter.h>
7#include <wreport/var.h>
8
9namespace wreport {
10namespace bufr {
11struct DispatchToSubsets;
12
13struct Decoder
14{
17 /* Output decoded variables */
18 BufrBulletin& out;
26 FILE* verbose_output = nullptr;
27
28 Decoder(const std::string& buf, const char* fname, size_t offset,
29 BufrBulletin& out);
30
31 void read_options(const BufrCodecOptions& opts);
32
33 void decode_sec1ed3();
34 void decode_sec1ed4();
35
36 /* Decode the message header only */
37 void decode_header();
38
39 /* Decode message data section after the header has been decoded */
40 void decode_data();
41};
42
44{
47
48 DecoderTarget(Input& in) : in(in) {}
49 virtual ~DecoderTarget() {}
50
58 virtual const Subset& reference_subset() const = 0;
59
63 virtual Varinfo lookup_info(unsigned pos) const = 0;
64
73
78 virtual const Var& decode_and_add_to_all(Varinfo info) = 0;
79
80 virtual const Var& decode_and_add_bitmap(const Tables& tables, Varcode code,
81 unsigned bitmap_size) = 0;
82
87 virtual void decode_and_set_attribute(Varinfo info, unsigned pos) = 0;
88
92 virtual void decode_and_add_b_value(Varinfo info) = 0;
93
99 Varinfo info, const bulletin::AssociatedField& field) = 0;
100
106
111 virtual int decode_c03_refval_override(unsigned bits) = 0;
112
114 virtual void print_last_variable_added(FILE* out) = 0;
115
118 virtual void print_last_attribute_added(FILE* out, Varcode code,
119 unsigned pos) = 0;
120};
121
123{
126
128
129 const Subset& reference_subset() const override;
130 Varinfo lookup_info(unsigned pos) const override;
132 const Var& decode_and_add_to_all(Varinfo info) override;
133 const Var& decode_and_add_bitmap(const Tables& tables, Varcode code,
134 unsigned bitmap_size) override;
135 void decode_and_set_attribute(Varinfo info, unsigned pos) override;
136 void decode_and_add_b_value(Varinfo info) override;
138 Varinfo info, const bulletin::AssociatedField& field) override;
140 int decode_c03_refval_override(unsigned bits) override;
141
142 void print_last_variable_added(FILE* out) override;
144 unsigned pos) override;
145};
146
148{
151
153 unsigned subset_count;
154
156
157 const Subset& reference_subset() const override;
158 Varinfo lookup_info(unsigned pos) const override;
160 const Var& decode_and_add_to_all(Varinfo info) override;
161 const Var& decode_and_add_bitmap(const Tables& tables, Varcode code,
162 unsigned bitmap_size) override;
163 void decode_and_set_attribute(Varinfo info, unsigned pos) override;
164 void decode_and_add_b_value(Varinfo info) override;
166 Varinfo info, const bulletin::AssociatedField& field) override;
168 int decode_c03_refval_override(unsigned bits) override;
169
170 void print_last_variable_added(FILE* out) override;
172 unsigned pos) override;
173
174protected:
175 void decode_b_value(Varinfo info,
176 std::function<void(unsigned, Var&&)> dest);
177};
178
180{
181 DecoderTarget& target;
182
183 DataSectionDecoder(Bulletin& bulletin, DecoderTarget& target);
184
189 void define_bitmap(unsigned bitmap_size) override;
190 void define_attribute(Varinfo info, unsigned pos) override;
191 void define_substituted_value(unsigned pos) override;
192 void define_variable(Varinfo info) override;
195};
196
198{
199protected:
206 void print_lead(Varcode code);
207 void print_lead_continued();
208
209public:
210 FILE* out;
211
218 unsigned indent = 0;
219
221 unsigned indent_step = 2;
222
224 FILE* out);
225
226 void b_variable(Varcode code) override;
227 void c_modifier(Varcode code, Opcodes& next) override;
228 void r_replication(Varcode code, Varcode delayed_code,
229 const Opcodes& ops) override;
230 void run_d_expansion(Varcode code) override;
235 void define_bitmap(unsigned bitmap_size) override;
236 void define_attribute(Varinfo info, unsigned pos) override;
237 void define_substituted_value(unsigned pos) override;
238 void define_variable(Varinfo info) override;
241};
242
243} // namespace bufr
244} // namespace wreport
245#endif
BUFR bulletin implementation.
Definition bulletin.h:228
Options used to configure BUFR decoding.
Definition bulletin.h:200
Storage for the decoded data of a BUFR or CREX message.
Definition bulletin.h:30
Represent a BUFR/CREX data subset as a list of decoded variables.
Definition subset.h:13
A physical variable.
Definition var.h:25
Binary buffer with bit-level read operations.
Definition input.h:48
String functions.
Definition benchmark.h:13
uint16_t Varcode
Holds the WMO variable code of a variable.
Definition fwd.h:12
Sequence of opcodes, as a slice of a Varcode vector.
Definition opcodes.h:20
Collection of BUFR/CREX tables used to work on a bulletin.
Definition tables.h:15
Information about a variable.
Definition varinfo.h:140
int decode_c03_refval_override(unsigned bits) override
Decode the given number of bits a signed integer, to use as a new value for B table reference value.
void decode_and_set_attribute(Varinfo info, unsigned pos) override
Decode an attribute with the given description, and add it to data at position pos.
void decode_and_add_raw_character_data(Varinfo info) override
Decode raw character data described by code and add it to the target subset(s)
Bulletin & out
Output bulletin.
Definition decoder.h:150
void decode_and_add_b_value_with_associated_field(Varinfo info, const bulletin::AssociatedField &field) override
Decode a B-table value with associated field, and add its value(s) to the target subset(s)
void decode_and_add_b_value(Varinfo info) override
Decode a B-table value and add its value(s) to the target subset(s)
const Var & decode_and_add_to_all(Varinfo info) override
Decode and add the same value to all datasets, return a reference to one of the variables added.
void print_last_attribute_added(FILE *out, Varcode code, unsigned pos) override
Print the value(s) of the last attributes(s) with the given code added to out.
const Subset & reference_subset() const override
Return the reference to a subset that is receiving the data currently decoded.
Varinfo lookup_info(unsigned pos) const override
Return information about a value previously stored at the given position.
unsigned subset_count
Number of subsets in data section.
Definition decoder.h:153
void print_last_variable_added(FILE *out) override
Print the value(s) of the last variable(s) added to out.
Var decode_uniform_b_value(Varinfo info) override
Decode a value that must always be the same across all datasets.
Definition decoder.h:180
void define_substituted_value(unsigned pos) override
Request processing of a substituted value corresponding to position pos in the list or previous varia...
void define_c03_refval_override(Varcode code) override
Request processing of a new value for the reference value of the given B code.
void define_variable(Varinfo info) override
Request processing, according to info, of a data variable.
void define_attribute(Varinfo info, unsigned pos) override
Request processing of an attribute encoded with info, related to the variable as position pos in the ...
void define_raw_character_data(Varcode code) override
Request processing of C05yyy raw character data.
unsigned define_associated_field_significance(Varinfo info) override
Request processing of an associated field significance variable (B31021).
unsigned define_delayed_replication_factor(Varinfo info) override
Request processing, according to info, of a data variabile that is significant for controlling the en...
void define_bitmap(unsigned bitmap_size) override
Request processing of a data present bitmap.
unsigned define_bitmap_delayed_replication_factor(Varinfo info) override
Request processing of a delayed replication factor variable used to encode the size of a bitmap.
void define_variable_with_associated_field(Varinfo info) override
Request processing, according to info, of a data variable.
Definition decoder.h:44
virtual int decode_c03_refval_override(unsigned bits)=0
Decode the given number of bits a signed integer, to use as a new value for B table reference value.
virtual void decode_and_add_b_value(Varinfo info)=0
Decode a B-table value and add its value(s) to the target subset(s)
virtual void decode_and_add_raw_character_data(Varinfo info)=0
Decode raw character data described by code and add it to the target subset(s)
Input & in
Input buffer.
Definition decoder.h:46
virtual void decode_and_add_b_value_with_associated_field(Varinfo info, const bulletin::AssociatedField &field)=0
Decode a B-table value with associated field, and add its value(s) to the target subset(s)
virtual Varinfo lookup_info(unsigned pos) const =0
Return information about a value previously stored at the given position.
virtual const Var & decode_and_add_to_all(Varinfo info)=0
Decode and add the same value to all datasets, return a reference to one of the variables added.
virtual void print_last_attribute_added(FILE *out, Varcode code, unsigned pos)=0
Print the value(s) of the last attributes(s) with the given code added to out.
virtual Var decode_uniform_b_value(Varinfo info)=0
Decode a value that must always be the same across all datasets.
virtual void print_last_variable_added(FILE *out)=0
Print the value(s) of the last variable(s) added to out.
virtual const Subset & reference_subset() const =0
Return the reference to a subset that is receiving the data currently decoded.
virtual void decode_and_set_attribute(Varinfo info, unsigned pos)=0
Decode an attribute with the given description, and add it to data at position pos.
Definition decoder.h:14
FILE * verbose_output
If set, be verbose and print a trace of decoding to the given file.
Definition decoder.h:26
Input in
Input data.
Definition decoder.h:16
bool conf_add_undef_attrs
True if undefined attributes are added to the output, else false.
Definition decoder.h:22
size_t expected_subsets
Number of expected subsets (read in decode_header, used in decode_data)
Definition decoder.h:20
unsigned optional_section_length
Optional section length decoded from the message.
Definition decoder.h:24
int decode_c03_refval_override(unsigned bits) override
Decode the given number of bits a signed integer, to use as a new value for B table reference value.
const Subset & reference_subset() const override
Return the reference to a subset that is receiving the data currently decoded.
Subset & out
Subset where decoded variables go.
Definition decoder.h:125
void decode_and_add_b_value(Varinfo info) override
Decode a B-table value and add its value(s) to the target subset(s)
Varinfo lookup_info(unsigned pos) const override
Return information about a value previously stored at the given position.
void decode_and_add_b_value_with_associated_field(Varinfo info, const bulletin::AssociatedField &field) override
Decode a B-table value with associated field, and add its value(s) to the target subset(s)
void print_last_attribute_added(FILE *out, Varcode code, unsigned pos) override
Print the value(s) of the last attributes(s) with the given code added to out.
void decode_and_set_attribute(Varinfo info, unsigned pos) override
Decode an attribute with the given description, and add it to data at position pos.
Var decode_uniform_b_value(Varinfo info) override
Decode a value that must always be the same across all datasets.
const Var & decode_and_add_to_all(Varinfo info) override
Decode and add the same value to all datasets, return a reference to one of the variables added.
void decode_and_add_raw_character_data(Varinfo info) override
Decode raw character data described by code and add it to the target subset(s)
void print_last_variable_added(FILE *out) override
Print the value(s) of the last variable(s) added to out.
void define_variable_with_associated_field(Varinfo info) override
Request processing, according to info, of a data variable.
unsigned indent
Current indent level.
Definition decoder.h:218
unsigned define_associated_field_significance(Varinfo info) override
Request processing of an associated field significance variable (B31021).
void run_d_expansion(Varcode code) override
Executes the expansion of code, which has been put on top of the opcode stack.
void c_modifier(Varcode code, Opcodes &next) override
Notify of a C modifier.
void define_substituted_value(unsigned pos) override
Request processing of a substituted value corresponding to position pos in the list or previous varia...
void define_c03_refval_override(Varcode code) override
Request processing of a new value for the reference value of the given B code.
void define_bitmap(unsigned bitmap_size) override
Request processing of a data present bitmap.
unsigned define_bitmap_delayed_replication_factor(Varinfo info) override
Request processing of a delayed replication factor variable used to encode the size of a bitmap.
void r_replication(Varcode code, Varcode delayed_code, const Opcodes &ops) override
Handle a replicated section.
unsigned define_delayed_replication_factor(Varinfo info) override
Request processing, according to info, of a data variabile that is significant for controlling the en...
unsigned indent_step
How many spaces in an indentation level.
Definition decoder.h:221
void print_lead(Varcode code)
Print line lead (indentation and formatted code)
void b_variable(Varcode code) override
Notify of a B variable entry.
void define_attribute(Varinfo info, unsigned pos) override
Request processing of an attribute encoded with info, related to the variable as position pos in the ...
void define_raw_character_data(Varcode code) override
Request processing of C05yyy raw character data.
void define_variable(Varinfo info) override
Request processing, according to info, of a data variable.
Definition associated_fields.h:13
Interpreter for data descriptor sections.
Definition interpreter.h:26