Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
Binary Little Endianness Parser
Description

Binary little endian parsers are designed to parse binary byte streams that are laid out in little endian.

Header
// forwards to <boost/spirit/home/qi/binary.hpp>
#include <boost/spirit/include/qi_binary.hpp>

Also, see Include Structure.

Namespace

Name

boost::spirit::little_word // alias: boost::spirit::qi::little_word

boost::spirit::little_dword // alias: boost::spirit::qi::little_dword

boost::spirit::little_qword // alias: boost::spirit::qi::little_qword

boost::spirit::little_bin_float // alias: boost::spirit::qi::little_bin_float

boost::spirit::little_bin_double // alias: boost::spirit::qi::little_bin_double

[Note] Note

little_qword is 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).

Model of

PrimitiveParser

Notation

w

A 16 bit binary value or a Lazy Argument that evaluates to a 16 bit binary value. This value is always in native endian.

dw

A 32 bit binary value or a Lazy Argument that evaluates to a 32 bit binary value. This value is always in native endian.

qw

A 64 bit binary value or a Lazy Argument that evaluates to a 64 bit binary value. This value is always in native endian.

f

A float binary value or a Lazy Argument that evaluates to a float binary value. This value is always in native endian.

d

A double binary value or a Lazy Argument that evaluates to a double binary value. This value is always in native endian.

Expression Semantics

Semantics of an expression is defined only where it differs from, or is not defined in PrimitiveParser.

Expression

Description

little_word

Matches any 16 bit little endian binary.

little_dword

Matches any 32 bit little endian binary.

little_qword

Matches any 64 bit little endian binary.

little_bin_float

Matches any float little endian binary.

little_bin_double

Matches any double little endian binary.

little_word(w)

Matches an exact 16 bit little endian binary.

little_dword(dw)

Matches an exact 32 bit little endian binary.

little_qword(qw)

Matches an exact 32 bit little endian binary.

little_bin_float(f)

Matches an exact float little endian binary.

little_bin_double(d)

Matches an exact double little endian binary.

Attributes

Expression

Attribute

little_word

boost::uint_least16_t

little_dword

boost::uint_least32_t

little_qword

boost::uint_least64_t

little_bin_float

float

little_bin_double

double

little_word(w)

unused

little_dword(dw)

unused

little_qword(qw)

unused

little_bin_float(f)

unused

little_bin_double(d)

unused

Complexity

O(N), where N is the number of bytes parsed

Example
[Note] Note

The test harness for the example(s) below is presented in the Basics Examples section.

Using declarations and variables:

using boost::spirit::qi::little_word;
using boost::spirit::qi::little_dword;
using boost::spirit::qi::little_qword;

boost::uint16_t us;
boost::uint32_t ui;
boost::uint64_t ul;

Basic usage of the little endian binary parsers:

test_parser_attr("\x01\x02", little_word, us); assert(us == 0x0201);
test_parser_attr("\x01\x02\x03\x04", little_dword, ui); assert(ui == 0x04030201);
test_parser_attr("\x01\x02\x03\x04\x05\x06\x07\x08", little_qword, ul);
assert(ul == 0x0807060504030201LL);

test_parser("\x01\x02", little_word(0x0201));
test_parser("\x01\x02\x03\x04", little_dword(0x04030201));
test_parser("\x01\x02\x03\x04\x05\x06\x07\x08",
    little_qword(0x0807060504030201LL));


PrevUpHomeNext