forked from boostorg/spirit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinary.qbk
508 lines (414 loc) · 23.8 KB
/
binary.qbk
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
507
508
[/==============================================================================
Copyright (C) 2001-2011 Hartmut Kaiser
Copyright (C) 2001-2011 Joel de Guzman
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
===============================================================================/]
[section:binary Binary Generators]
This module includes different generators allowing to output binary data.
It includes generators for default, little, and big endian binary output and
a `pad` generator allowing to control padding of the generated output
stream.
[heading Module Header]
// forwards to <boost/spirit/home/karma/binary.hpp>
#include <boost/spirit/include/karma_binary.hpp>
Also, see __include_structure__.
[/////////////////////////////////////////////////////////////////////////////]
[section:binary_native Binary Native Endianness Generators]
[heading Description]
The binary native endianness generators described in this section are used to
emit binary byte streams laid out conforming to the native endianness (byte
order) of the target architecture.
[heading Header]
// forwards to <boost/spirit/home/karma/binary.hpp>
#include <boost/spirit/include/karma_binary.hpp>
Also, see __include_structure__.
[heading Namespace]
[table
[[Name]]
[[`boost::spirit::byte_ // alias: boost::spirit::karma::byte_` ]]
[[`boost::spirit::word // alias: boost::spirit::karma::word` ]]
[[`boost::spirit::dword // alias: boost::spirit::karma::dword` ]]
[[`boost::spirit::qword // alias: boost::spirit::karma::qword` ]]
[[`boost::spirit::bin_float // alias: boost::spirit::karma::bin_float` ]]
[[`boost::spirit::bin_double // alias: boost::spirit::karma::bin_double` ]]
]
[note The generators `qword` and `qword(qw)` are only available on
platforms where the preprocessor constant `BOOST_HAS_LONG_LONG` is
defined (i.e. on platforms having native support for `unsigned long long`
(64 bit) integer types).]
[heading Model of]
[:__primitive_generator_concept__]
[variablelist Notation
[[`b`] [A single byte (8 bit binary value) or a __karma_lazy_argument__
that evaluates to a single byte]]
[[`w`] [A 16 bit binary value or a __karma_lazy_argument__ that
evaluates to a 16 bit binary value. This value is always
interpreted using native endianness.]]
[[`dw`] [A 32 bit binary value or a __karma_lazy_argument__ that
evaluates to a 32 bit binary value. This value is always
interpreted using native endianness.]]
[[`qw`] [A 64 bit binary value or a __karma_lazy_argument__ that
evaluates to a 64 bit binary value. This value is always
interpreted using native endianness.]]
[[`f`] [A float binary value or a __karma_lazy_argument__ that
evaluates to a float binary value. This value is always
interpreted using native endianness.]]
[[`d`] [A double binary value or a __karma_lazy_argument__ that
evaluates to a double binary value. This value is always
interpreted using native endianness.]]
]
[heading Expression Semantics]
Semantics of an expression is defined only where it differs from, or is
not defined in __primitive_generator_concept__.
[table
[[Expression] [Description]]
[[`byte_`] [Output the binary representation of the least
significant byte of the mandatory attribute. This
generator never fails (unless the underlying
output stream reports an error).]]
[[`word`] [Output the binary representation of the least
significant 16 bits of the mandatory attribute
in native endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`dword`] [Output the binary representation of the least
significant 32 bits of the mandatory attribute
in native endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`qword`] [Output the binary representation of the least
significant 64 bits of the mandatory attribute
in native endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`bin_float`] [Output the binary representation of the mandatory
float attribute in native endian representation.
This generator never fails (unless the underlying
output stream reports an error).]]
[[`bin_double`] [Output the binary representation of the mandatory
double attribute in native endian representation.
This generator never fails (unless the underlying
output stream reports an error).]]
[[`byte_(b)`] [Output the binary representation of the least
significant byte of the immediate parameter. This
generator never fails (unless the underlying
output stream reports an error).]]
[[`word(w)`] [Output the binary representation of the least
significant 16 bits of the immediate parameter
in native endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`dword(dw)`] [Output the binary representation of the least
significant 32 bits of the immediate parameter
in native endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`qword(qw)`] [Output the binary representation of the least
significant 64 bits of the immediate parameter
in native endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`bin_float(f)`] [Output the binary representation of the immediate
float parameter in native endian representation.
This generator never fails (unless the underlying
output stream reports an error).]]
[[`bin_double(d)`] [Output the binary representation of the immediate
double parameter in native endian representation.
This generator never fails (unless the underlying
output stream reports an error).]]
]
[heading Attributes]
[table
[[Expression] [Attribute]]
[[`byte_`] [`boost::uint_least8_t`, attribute is mandatory
(otherwise compilation will fail)]]
[[`word`] [`boost::uint_least16_t`, attribute is mandatory
(otherwise compilation will fail)]]
[[`dword`] [`boost::uint_least32_t`, attribute is mandatory
(otherwise compilation will fail)]]
[[`qword`] [`boost::uint_least64_t`, attribute is mandatory
(otherwise compilation will fail)]]
[[`bin_float`] [`float`, attribute is mandatory
(otherwise compilation will fail)]]
[[`bin_double`] [`double`, attribute is mandatory
(otherwise compilation will fail)]]
[[`byte_(b)`] [__unused__]]
[[`word(w)`] [__unused__]]
[[`dword(dw)`] [__unused__]]
[[`qword(qw)`] [__unused__]]
[[`bin_float(f)`] [__unused__]]
[[`bin_double(d)`] [__unused__]]
]
[note In addition to their usual attribute of type `Attrib` all listed generators
accept an instance of a `boost::optional<Attrib>` as well. If the
`boost::optional<>` is initialized (holds a value) the generators behave
as if their attribute was an instance of `Attrib` and emit the value stored
in the `boost::optional<>`. Otherwise the generators will fail.]
[heading Complexity]
[:O(N), where N is the number of bytes emitted by the binary generator]
[heading Example]
[note The test harness for the example(s) below is presented in the
__karma_basics_examples__ section.]
Some includes:
[reference_karma_includes]
Some using declarations:
[reference_karma_using_declarations_native_binary]
Basic usage of the native binary generators with some results for little endian
platforms:
[reference_karma_native_binary_little]
Basic usage of the native binary generators with some results for big endian
platforms:
[reference_karma_native_binary_big]
[endsect]
[/////////////////////////////////////////////////////////////////////////////]
[section:binary_little Binary Little Endianness Generators]
[heading Description]
The little native endianness generators described in this section are used to
emit binary byte streams laid out conforming to the little endianness byte
order.
[heading Header]
// forwards to <boost/spirit/home/karma/binary.hpp>
#include <boost/spirit/include/karma_binary.hpp>
Also, see __include_structure__.
[heading Namespace]
[table
[[Name]]
[[`boost::spirit::little_word // alias: boost::spirit::karma::little_word` ]]
[[`boost::spirit::little_dword // alias: boost::spirit::karma::little_dword` ]]
[[`boost::spirit::little_qword // alias: boost::spirit::karma::little_qword` ]]
[[`boost::spirit::little_bin_float // alias: boost::spirit::karma::little_bin_float` ]]
[[`boost::spirit::little_bin_double // alias: boost::spirit::karma::little_bin_double` ]]
]
[note The generators `little_qword` and `little_qword(qw)` are only available on
platforms where the preprocessor constant `BOOST_HAS_LONG_LONG` is
defined (i.e. on platforms having native support for `unsigned long long`
(64 bit) integer types).]
[heading Model of]
[:__primitive_generator_concept__]
[variablelist Notation
[[`w`] [A 16 bit binary value or a __karma_lazy_argument__ that
evaluates to a 16 bit binary value. This value is always
interpreted using native endianness.]]
[[`dw`] [A 32 bit binary value or a __karma_lazy_argument__ that
evaluates to a 32 bit binary value. This value is always
interpreted using native endianness.]]
[[`qw`] [A 64 bit binary value or a __karma_lazy_argument__ that
evaluates to a 64 bit binary value. This value is always
interpreted using native endianness.]]
[[`f`] [A float binary value or a __karma_lazy_argument__ that
evaluates to a float binary value. This value is always
interpreted using native endianness.]]
[[`d`] [A double binary value or a __karma_lazy_argument__ that
evaluates to a double binary value. This value is always
interpreted using native endianness.]]
]
[heading Expression Semantics]
Semantics of an expression is defined only where it differs from, or is
not defined in __primitive_generator_concept__.
[table
[[Expression] [Description]]
[[`little_word`] [Output the binary representation of the least
significant 16 bits of the mandatory attribute
in little endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`little_dword`] [Output the binary representation of the least
significant 32 bits of the mandatory attribute
in little endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`little_qword`] [Output the binary representation of the least
significant 64 bits of the mandatory attribute
in little endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`little_bin_float`] [Output the binary representation of the mandatory
float attribute in little endian representation.
This generator never fails (unless the underlying
output stream reports an error).]]
[[`little_bin_double`] [Output the binary representation of the mandatory
double attribute in little endian representation.
This generator never fails (unless the underlying
output stream reports an error).]]
[[`little_word(w)`] [Output the binary representation of the least
significant 16 bits of the immediate parameter
in little endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`little_dword(dw)`] [Output the binary representation of the least
significant 32 bits of the immediate parameter
in little endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`little_qword(qw)`] [Output the binary representation of the least
significant 64 bits of the immediate parameter
in little endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`little_bin_float(f)`] [Output the binary representation of the immediate
float parameter in little endian representation.
This generator never fails (unless the underlying
output stream reports an error).]]
[[`little_bin_double(d)`] [Output the binary representation of the immediate
double parameter in little endian representation.
This generator never fails (unless the underlying
output stream reports an error).]]
]
[heading Attributes]
[table
[[Expression] [Attribute]]
[[`little_word`] [`boost::uint_least16_t`, attribute is mandatory
(otherwise compilation will fail)]]
[[`little_dword`] [`boost::uint_least32_t`, attribute is mandatory
(otherwise compilation will fail)]]
[[`little_qword`] [`boost::uint_least64_t`, attribute is mandatory
(otherwise compilation will fail)]]
[[`little_bin_float`] [`float`, attribute is mandatory
(otherwise compilation will fail)]]
[[`little_bin_double`] [`double`, attribute is mandatory
(otherwise compilation will fail)]]
[[`little_word(w)`] [__unused__]]
[[`little_dword(dw)`] [__unused__]]
[[`little_qword(qw)`] [__unused__]]
[[`little_bin_float(f)`] [__unused__]]
[[`little_bin_double(d)`] [__unused__]]
]
[heading Complexity]
[:O(N), where N is the number of bytes emitted by the binary generator]
[heading Example]
[note The test harness for the example(s) below is presented in the
__karma_basics_examples__ section.]
Some includes:
[reference_karma_includes]
Some using declarations:
[reference_karma_using_declarations_little_binary]
Basic usage of the little binary generators:
[reference_karma_little_binary]
[endsect]
[/////////////////////////////////////////////////////////////////////////////]
[section:binary_big Binary Big Endianness Generators]
[heading Description]
The big native endianness generators described in this section are used to
emit binary byte streams laid out conforming to the big endianness byte
order.
[heading Header]
// forwards to <boost/spirit/home/karma/binary.hpp>
#include <boost/spirit/include/karma_binary.hpp>
Also, see __include_structure__.
[heading Namespace]
[table
[[Name]]
[[`boost::spirit::big_word // alias: boost::spirit::karma::big_word` ]]
[[`boost::spirit::big_dword // alias: boost::spirit::karma::big_dword` ]]
[[`boost::spirit::big_qword // alias: boost::spirit::karma::big_qword` ]]
[[`boost::spirit::big_bin_float // alias: boost::spirit::karma::big_bin_float` ]]
[[`boost::spirit::big_bin_double // alias: boost::spirit::karma::big_bin_double` ]]
]
[note The generators `big_qword` and `big_qword(qw)` are only available on
platforms where the preprocessor constant `BOOST_HAS_LONG_LONG` is
defined (i.e. on platforms having native support for `unsigned long long`
(64 bit) integer types).]
[heading Model of]
[:__primitive_generator_concept__]
[variablelist Notation
[[`w`] [A 16 bit binary value or a __karma_lazy_argument__ that
evaluates to a 16 bit binary value. This value is always
interpreted using native endianness.]]
[[`dw`] [A 32 bit binary value or a __karma_lazy_argument__ that
evaluates to a 32 bit binary value. This value is always
interpreted using native endianness.]]
[[`qw`] [A 64 bit binary value or a __karma_lazy_argument__ that
evaluates to a 64 bit binary value. This value is always
interpreted using native endianness.]]
[[`f`] [A float binary value or a __karma_lazy_argument__ that
evaluates to a float binary value. This value is always
interpreted using native endianness.]]
[[`d`] [A double binary value or a __karma_lazy_argument__ that
evaluates to a double binary value. This value is always
interpreted using native endianness.]]
]
[heading Expression Semantics]
Semantics of an expression is defined only where it differs from, or is
not defined in __primitive_generator_concept__.
[table
[[Expression] [Description]]
[[`big_word`] [Output the binary representation of the least
significant 16 bits of the mandatory attribute
in big endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`big_dword`] [Output the binary representation of the least
significant 32 bits of the mandatory attribute
in big endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`big_qword`] [Output the binary representation of the least
significant 64 bits of the mandatory attribute
in big endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`big_bin_float`] [Output the binary representation of the mandatory
float attribute in big endian representation.
This generator never fails (unless the underlying
output stream reports an error).]]
[[`big_bin_double`] [Output the binary representation of the mandatory
double attribute in big endian representation.
This generator never fails (unless the underlying
output stream reports an error).]]
[[`big_word(w)`] [Output the binary representation of the least
significant 16 bits of the immediate parameter
in big endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`big_dword(dw)`] [Output the binary representation of the least
significant 32 bits of the immediate parameter
in big endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`big_qword(qw)`] [Output the binary representation of the least
significant 64 bits of the immediate parameter
in big endian representation. This generator
never fails (unless the underlying output stream
reports an error).]]
[[`big_bin_float(f)`] [Output the binary representation of the immediate
float parameter in big endian representation.
This generator never fails (unless the underlying
output stream reports an error).]]
[[`big_bin_double(d)`] [Output the binary representation of the immediate
double parameter in big endian representation.
This generator never fails (unless the underlying
output stream reports an error).]]
]
[heading Attributes]
[table
[[Expression] [Attribute]]
[[`big_word`] [`boost::uint_least16_t`, attribute is mandatory
(otherwise compilation will fail)]]
[[`big_dword`] [`boost::uint_least32_t`, attribute is mandatory
(otherwise compilation will fail)]]
[[`big_qword`] [`boost::uint_least64_t`, attribute is mandatory
(otherwise compilation will fail)]]
[[`big_bin_float`] [`float`, attribute is mandatory
(otherwise compilation will fail)]]
[[`big_bin_double`] [`double`, attribute is mandatory
(otherwise compilation will fail)]]
[[`big_word(w)`] [__unused__]]
[[`big_dword(dw)`] [__unused__]]
[[`big_qword(qw)`] [__unused__]]
[[`big_bin_float(f)`] [__unused__]]
[[`big_bin_double(d)`] [__unused__]]
]
[heading Complexity]
[:O(N), where N is the number of bytes emitted by the binary generator]
[heading Example]
[note The test harness for the example(s) below is presented in the
__karma_basics_examples__ section.]
Some includes:
[reference_karma_includes]
Some using declarations:
[reference_karma_using_declarations_big_binary]
Basic usage of the big binary generators:
[reference_karma_big_binary]
[endsect]
[endsect]