auth 0.0.1
Authenticated computation with C++26 modules
Loading...
Searching...
No Matches
serialization.ccm File Reference

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;
Include dependency graph for serialization.ccm:

Go to the source code of this file.

Classes

struct  auth::writer
 Appends deterministic, byte-aligned fields to an owned buffer. More...
struct  auth::reader
 Reads checked fields from borrowed bytes, advancing a byte offset. More...

Typedefs

using auth::bytes = std::vector<std::uint8_t>
 An owned buffer of serialized bytes.

Functions

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.

Detailed Description

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.

Function Documentation

◆ 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
TDefault-constructible, deserializable payload type.
Parameters
dataBorrowed 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_errorIf 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
valueValue 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.