Binary Big Endian

| Home | Libraries | People | FAQ | More

##### Binary Big Endian

###### Description

Binary big endian parsers are designed to parse binary byte streams that are laid out in big 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::big_word // alias: boost::spirit::qi::big_word`
`boost::spirit::big_dword // alias: boost::spirit::qi::big_dword`
`boost::spirit::big_qword // alias: boost::spirit::qi::big_qword`

| Note
`big_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.

###### Expression Semantics

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

Expression | Description
--- | ---
`big_word` | Matches any 16 bit big endian binary.
`big_dword` | Matches any 32 bit big endian binary.
`big_qword` | Matches any 64 bit big endian binary.
`big_word(w)` | Matches an exact 16 bit big endian binary.
`big_dword(dw)` | Matches an exact 32 bit big endian binary.
`big_qword(qw)` | Matches an exact 32 bit big endian binary.

###### Attributes

Expression | Attribute
--- | ---
`big_word` | `boost::uint_least16_t`
`big_dword` | `boost::uint_least32_t`
`big_qword` | `boost::uint_least64_t`
`big_word(w)` | `unused`
`big_dword(dw)` | `unused`
`big_qword(qw)` | `unused`

###### Complexity

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

###### Example

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

Using declarations and variables:

    using boost::spirit::qi::big_word;
    using boost::spirit::qi::big_dword;
    using boost::spirit::qi::big_qword;

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

Basic usage of the big endian binary parsers:

    test_parser_attr("\x01\x02", big_word, us); assert(us ==  0x0102);
    test_parser_attr("\x01\x02\x03\x04", big_dword, ui); assert(ui == 0x01020304);
    test_parser_attr("\x01\x02\x03\x04\x05\x06\x07\x08", big_qword, ul);
    assert(0x0102030405060708LL);

    test_parser("\x01\x02", big_word(0x0102));
    test_parser("\x01\x02\x03\x04", big_dword(0x01020304));
    test_parser("\x01\x02\x03\x04\x05\x06\x07\x08",
        big_qword(0x0102030405060708LL));