|
Binary Serialize
|
Extract a sequence in network byte order from a std::byte buffer into the provided container.
More...
#include <binary_serialize.hpp>
Public Member Functions | |
| fixed_size_byte_array () noexcept | |
| Default construct the @ fixed_size_byte_array. | |
| std::size_t | size () const noexcept |
| Return the size of the data which has been written into the buffer. | |
| void | resize (std::size_t sz) noexcept |
| Increase the logical size, allowing bytes to be appended. | |
| std::byte * | data () noexcept |
| Return a pointer to the beginning of the buffer. | |
| void | clear () noexcept |
| Logically reset so that new data can be written into the buffer at the beginning. | |
Extract a sequence in network byte order from a std::byte buffer into the provided container.
Fill a container with a sequence of elements. See append_sequence for additional comments on sequence.
| buf | Buffer of std::bytes containing a sequence of objects to be extracted, with the count in front. |
| Cnt | Type of the count value, which prepends the sequence of elements. The type determines the size (in bytes) of the count value (e.g. std::uint16_t would specify a 16-bit unsigned count). |
| Container | Container type, which must provide a value_type declaration, a default constructor, an emplace_back method, and a copy or move constructor. |
sizeof(T) bytes.Append a sequence of elements, including the count, into a std::byte buffer using the lower level append_val function.
A sequence is defined as an array of elements of type T, along with the number of elements. When appending to a stream of std::bytes, the count is first converted into network byte order and then appended, then the same performed for each element. The number of bits in the count is specified as the type of the count. For example a std::vector of 16-bit ints with an 8-bit count can be appended to the buffer as an 8-bit integer, and then successive 16-bit integers.
| buf | Buffer of std::bytes containing an object of type T in network byte order. |
| cnt | Number of elements in the sequence. |
| start | Iterator pointing to the start of the sequence. |
| end | Iterator pointing to the end of the sequence. |
std::byte buffer.Adapt a std::array so that a fixed size std::byte array can be used with the chops::marshall function template as the Buf template parameter.
This class provides three methods (size, resize, data) as required by the Buf parameter type in the chops::marshall function template.
The logical size of the buffer is tracked. If resize is called and there is not enough room in the buffer an assert is fired.
|
inlinenoexcept |
Return a pointer to the beginning of the buffer.
|
inlinenoexcept |
Increase the logical size, allowing bytes to be appended.
| sz | New logical size. |
|
inlinenoexcept |
Return the size of the data which has been written into the buffer.
resize method.