AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::codec::FormatCodec< F > Struct Template Reference

Codec of a data format: media type, options of each side ( FormatPolicy ), serialization and deserialization ( Serializer , Deserializer concepts). More...

#include <formatCodec.hpp>

Inheritance diagram for anch::codec::FormatCodec< F >:
Collaboration diagram for anch::codec::FormatCodec< F >:

Public Types

using Options = typename F::Options

Static Public Member Functions

static std::string_view mediaType () noexcept
static Options & options (anch::codec::Side side)
template<typename T>
requires anch::codec::FormatSerializer<F, T>
static void serialize (const T &value, std::ostream &out)
template<typename T>
requires anch::codec::FormatSerializer<F, T>
static void serialize (const T &value, std::ostream &out, anch::codec::Side side)
template<typename T>
requires anch::codec::FormatDeserializer<F, T>
static void deserialize (T &value, std::istream &input)
template<typename T>
requires anch::codec::FormatDeserializer<F, T>
static void deserialize (T &value, std::istream &input, anch::codec::Side side)

Detailed Description

template<anch::codec::DataFormat F>
struct anch::codec::FormatCodec< F >

Codec of a data format: media type, options of each side ( FormatPolicy ), serialization and deserialization ( Serializer , Deserializer concepts).

Values are handled when the format handles them ( FormatSerializer , FormatDeserializer ): formats constrain their types (described objects for anch-json and anch-csv), so that values described by an external schema (Protobuf messages, Thrift structures) are left to the codecs of their format. Options of each side are shared by the program: a codec plugin instantiates its FormatCodec in its library ( anch::codec::Json is FormatCodec<anch::json::JsonFormat> , anch::codec::Csv is FormatCodec<anch::csv::CsvFormat> ).

Template Parameters
Fthe format type
Author
Vincent Lachenal
Since
0.3

Member Typedef Documentation

◆ Options

using anch::codec::FormatCodec< F >::Options = typename F::Options

Format options type

Member Function Documentation

◆ deserialize() [1/2]

template<typename T>
requires anch::codec::FormatDeserializer<F, T>
void anch::codec::FormatCodec< F >::deserialize ( T & value,
std::istream & input )
static

Deserialize value with the format default options

Parameters
valuethe value to fill
inputthe input stream

◆ deserialize() [2/2]

template<typename T>
requires anch::codec::FormatDeserializer<F, T>
void anch::codec::FormatCodec< F >::deserialize ( T & value,
std::istream & input,
anch::codec::Side side )
static

Deserialize value with the options of a side

Parameters
valuethe value to fill
inputthe input stream
sidethe side
Exceptions
ContentTooLargeinput is larger than a limit (translated by FormatPolicy )

◆ mediaType()

std::string_view anch::codec::FormatCodec< F >::mediaType ( )
staticnoexcept

Media type

Returns
F::MEDIA_TYPE

◆ options()

Options & anch::codec::FormatCodec< F >::options ( anch::codec::Side side)
static

Options of a side: copied from F::defaultOptions() on first use, then configured by FormatPolicy . They can be changed at application initialization (they are not protected against concurrent changes).

Parameters
sidethe side
Returns
the options of the side

◆ serialize() [1/2]

template<typename T>
requires anch::codec::FormatSerializer<F, T>
void anch::codec::FormatCodec< F >::serialize ( const T & value,
std::ostream & out )
static

Serialize value with the format default options

Parameters
valuethe value
outthe output stream

◆ serialize() [2/2]

template<typename T>
requires anch::codec::FormatSerializer<F, T>
void anch::codec::FormatCodec< F >::serialize ( const T & value,
std::ostream & out,
anch::codec::Side side )
static

Serialize value with the options of a side

Parameters
valuethe value
outthe output stream
sidethe side

The documentation for this struct was generated from the following file: