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

#include <codecs.hpp>

Collaboration diagram for anch::codec::Codecs< Cs >:

Static Public Member Functions

static std::vector< anch::codec::MediaType > mediaTypes ()
template<typename T>
static bool deserialize (T &value, std::istream &input, const anch::codec::MediaType &contentType, anch::codec::Side side)
template<typename T>
static std::optional< anch::codec::MediaType > serialize (const T &value, std::ostream &out, const std::vector< anch::codec::MediaType > &accept, anch::codec::Side side)

Static Public Attributes

template<typename T>
static constexpr bool SERIALIZES = (anch::codec::Serializer<Cs, T> || ...)
template<typename T>
static constexpr bool DESERIALIZES = (anch::codec::Deserializer<Cs, T> || ...)

Detailed Description

template<typename... Cs>
struct anch::codec::Codecs< Cs >

List of codecs, resolved at compilation: selects the codec of a content type (reading) or of an Accept negotiation (writing).
anch::codec::Available (codec/all.hpp , target anch::codec-all ) lists the codecs of the formats built with the framework.

Template Parameters
Csthe codecs, by preference order
Author
Vincent Lachenal
Since
0.3

Member Function Documentation

◆ deserialize()

template<typename... Cs>
template<typename T>
bool anch::codec::Codecs< Cs >::deserialize ( T & value,
std::istream & input,
const anch::codec::MediaType & contentType,
anch::codec::Side side )
static

Deserialize value with the first codec which deserializes T values and whose media type has the type/subtype of the content type (parameters are given to the codec)

Template Parameters
Tthe value type
Parameters
valuethe value to fill
inputthe input stream
contentTypethe content type
sidethe side which deserializes value
Returns
false when no codec handles the content type (value and input are untouched)

◆ mediaTypes()

template<typename... Cs>
std::vector< anch::codec::MediaType > anch::codec::Codecs< Cs >::mediaTypes ( )
static

Get codecs media types

Returns
the media types, in codecs order
Exceptions
std::invalid_argumentwhen a codec media type is invalid

◆ serialize()

template<typename... Cs>
template<typename T>
std::optional< anch::codec::MediaType > anch::codec::Codecs< Cs >::serialize ( const T & value,
std::ostream & out,
const std::vector< anch::codec::MediaType > & accept,
anch::codec::Side side )
static

Serialize value with the codec selected by Accept negotiation (negotiate) among the codecs which serialize T values

Template Parameters
Tthe value type
Parameters
valuethe value
outthe output stream
acceptthe accepted media ranges ; empty means that every media type is accepted (first codec)
sidethe side which serializes value
Returns
the content type of the serialized value, empty when no codec is acceptable (nothing is written)

Member Data Documentation

◆ DESERIALIZES

template<typename... Cs>
template<typename T>
bool anch::codec::Codecs< Cs >::DESERIALIZES = (anch::codec::Deserializer<Cs, T> || ...)
staticconstexpr

true when one of the codecs deserializes T values

◆ SERIALIZES

template<typename... Cs>
template<typename T>
bool anch::codec::Codecs< Cs >::SERIALIZES = (anch::codec::Serializer<Cs, T> || ...)
staticconstexpr

true when one of the codecs serializes T values


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