Checked binary serialization with one definition for reading and writing.
More...
#include <array>
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <span>
#include <type_traits>
#include <utility>
#include <variant>
#include <vector>
import auth.error;
Go to the source code of this file.
|
|
using | auth::bytes = std::vector<std::uint8_t> |
| | An owned buffer of serialized bytes.
|
|
| template<class T> |
| bytes | auth::encode (const T &value) |
| | Serializes a value to an owned byte buffer.
|
| template<class T> |
| std::pair< T, const std::uint8_t * > | auth::decode (std::span< const std::uint8_t > data) |
| | Decodes one value, leaving subsequent bytes for the caller.
|
Checked binary serialization with one definition for reading and writing.
The shared stream interface follows Glenn Fiedler's Serialization Strategies. A type describes its fields once; the stream supplies the direction and bounds checks. This implementation uses byte-aligned fields and exceptions for errors.
Definition in file serialization.ccm.
◆ decode()
template<class T>
| std::pair< T, const std::uint8_t * > auth::decode |
( |
std::span< const std::uint8_t > | data | ) |
|
|
export |
Decodes one value, leaving subsequent bytes for the caller.
- Template Parameters
-
| T | Default-constructible, deserializable payload type. |
- Parameters
-
| data | Borrowed input bytes, possibly followed by more values. |
- Returns
- The value and a pointer immediately after its consumed bytes. The pointer borrows data's storage; the caller retains the original end.
- Exceptions
-
| auth_error | If a primitive field is truncated or malformed. |
- Note
- Custom serializer and construction exceptions propagate. Trailing bytes are permitted, and a zero-byte value returns the original starting pointer.
Definition at line 202 of file serialization.ccm.
◆ encode()
template<class T>
| bytes auth::encode |
( |
const T & | value | ) |
|
|
export |
Serializes a value to an owned byte buffer.
- Parameters
-
| value | Value to encode, without modifying it. |
- Returns
- The bytes emitted by its fields or custom serialize method.
- Note
- Serialization and allocation exceptions propagate.
Definition at line 186 of file serialization.ccm.