class BinaryDecoder

Defined at line 51 of file ../../src/media/audio/drivers/intel-hda/controller/binary_decoder.h

Light-weight class for decoding packed structs in a safe manner.

Each operation returns either a specified struct or an error

indicating that the read would go out of bounds of the original input

buffer. Successful reads consume bytes from the buffer, while failed

reads don't modify internal state.

The code avoids performing unaligned reads.

A typical use will be as follows:

// Give the decoder a reference to binary data.

BinaryDecoder decoder(cpp20::span

<const

uint8_t>(...));

// Read some structures.

StatusOr

<int32

_t> a = decoder.Read

<int32

_t>();

StatusOr

<MyStruct

> b = decoder.Read

<MyStruct

>();

StatusOr

<OtherStruct

> c = decoder.Read

<OtherStruct

>();

// Read off a range of 16 bytes.

StatusOr

<cpp20

::span

<const

uint8_t>> bytes = decoder.Read(16);

// Read off a struct that encodes its length as a field.

//

// The result will consist of a "MyStruct" and additional payload data

// as a byte range.

StatusOr

<std

::tuple

<MyStruct

, cpp20::span

<const

uint8_t>>> data

= decoder.VariableLengthRead

<MyStruct

>(

&MyStruct

::length);

Public Methods

void BinaryDecoder (cpp20::span<const uint8_t> data)

Defined at line 53 of file ../../src/media/audio/drivers/intel-hda/controller/binary_decoder.h

zx::result<cpp20::span<const uint8_t>> Read (size_t size)

Read off the given number of bytes from the beginning of the buffer.

Defined at line 56 of file ../../src/media/audio/drivers/intel-hda/controller/binary_decoder.h

template <typename T>
zx_status_t Read (T * result)

Fetch a structure of type |T| from the buffer, and write it to |result|.

|result| will contain unpacked data iff Status is ok.

|T| should be a standard layout, trivially copyable type that can be initialized via memcpy().

Defined at line 74 of file ../../src/media/audio/drivers/intel-hda/controller/binary_decoder.h

template <typename T>
zx::result<T> Read ()

Fetch a structure of type |T| from the buffer.

|T| should be a POD type that can be initialized via memcpy().

Defined at line 91 of file ../../src/media/audio/drivers/intel-hda/controller/binary_decoder.h

template <typename T, typename F>
zx::result<std::tuple<T, cpp20::span<const uint8_t>>> VariableLengthRead (F T::* length_field)

Fetch a variable-length structure of type |T| which is followed by

some number of bytes, specified by a field |F|.

|T| should be a POD type that can be initialized via memcpy().

|T::length_field| must be castable to size_t.

Defined at line 107 of file ../../src/media/audio/drivers/intel-hda/controller/binary_decoder.h