template <typename IntType>
cardano::util::BytePacker struct

Object for packing and unpacking bytes as integers.

Template parameters
IntType The integer type to pack to or unpack from.

Public static functions

static auto pack(IntType value, Endianness endianness = Endianness::BigEndian) > -> auto
Pack an integer into an array of bytes.
static auto unpack(std::span<const uint8_t, sizeof(IntType)> bytes, Endianness endianness = Endianness::BigEndian) →  IntType
Unpack a span of bytes as an integer.

Function documentation

template <typename IntType>
static auto cardano::util::BytePacker::pack(IntType value, Endianness endianness = Endianness::BigEndian) >

Pack an integer into an array of bytes.

Parameters
value The IntType value to pack.
endianness Specify big or little endianess (default: big).
Returns A fixed size byte array of length sizeof(IntType).

template <typename IntType>
static IntType cardano::util::BytePacker::unpack(std::span<const uint8_t, sizeof(IntType)> bytes, Endianness endianness = Endianness::BigEndian)

Unpack a span of bytes as an integer.

Parameters
bytes Bytes to unpack, must be fixed length of sizeof(IntType).
endianness Specify big or little endianess (default: big).
Returns The unpacked integer of IntType.