#include <cpp/a11/data/serialization.h>
|
| template<typename T > |
| using | Serializer = std::function< absl::StatusOr< Chunk >(const T &)> |
| | Callable turning a T into a Chunk.
|
| |
| template<typename T > |
| using | Deserializer = std::function< absl::StatusOr< T >(const Chunk &)> |
| | Callable reconstructing a T from a Chunk.
|
| |
◆ Deserializer
Callable reconstructing a T from a Chunk.
◆ Serializer
Callable turning a T into a Chunk.
◆ SerializationRegistry() [1/2]
| a11::data::SerializationRegistry::SerializationRegistry |
( |
bool |
register_defaults = false | ) |
|
|
explicit |
Constructs a registry.
- Parameters
-
| register_defaults | When true, install the JSON and MessagePack codecs; otherwise start empty. |
◆ ~SerializationRegistry()
| a11::data::SerializationRegistry::~SerializationRegistry |
( |
| ) |
|
◆ SerializationRegistry() [2/2]
◆ deserializer_count()
| size_t a11::data::SerializationRegistry::deserializer_count |
( |
| ) |
const |
Number of registered deserializers.
◆ FromChunk()
template<typename T >
| absl::StatusOr< T > a11::data::SerializationRegistry::FromChunk |
( |
const Chunk & |
chunk, |
|
|
const std::vector< std::string > & |
mimetype_patterns = {} |
|
) |
| const |
|
inline |
Deserializes chunk into a value of type T.
- Parameters
-
| chunk | Chunk to decode. |
| mimetype_patterns | Optional ordered media-type selectors (may use wildcards); the first that matches the chunk is used. When empty, the chunk's own mimetype selects the codec. A selector chooses the representation only – T is what decides the result type, so the chunk's own type parameter does not have to agree with it. |
- Returns
- The decoded value, or an error when no codec matches or the data cannot be read as a
T.
◆ operator=()
◆ Register()
template<typename T >
| absl::Status a11::data::SerializationRegistry::Register |
( |
const std::string & |
type_name, |
|
|
const std::string & |
mimetype, |
|
|
Serializer< T > |
serializer, |
|
|
Deserializer< T > |
deserializer |
|
) |
| |
|
inline |
Atomically registers a serializer/deserializer pair for T.
On failure to register the deserializer, the serializer added by this call is rolled back.
- Parameters
-
| type_name | Wire tag identifying T in serialized chunks. Tags a format already describes (json, object, string, ...) are not written; the media type alone says as much. |
| mimetype | Exact media type for both codecs. |
| serializer | Callable converting a T to a Chunk. |
| deserializer | Callable reconstructing a T from a Chunk. |
- Returns
- OK on success, or the first error encountered.
◆ RegisterDefaults()
| absl::Status a11::data::SerializationRegistry::RegisterDefaults |
( |
| ) |
|
Installs the standard JSON and MessagePack codecs.
◆ RegisterDeserializer()
template<typename T >
| absl::Status a11::data::SerializationRegistry::RegisterDeserializer |
( |
std::string |
type_name, |
|
|
const std::string & |
mimetype, |
|
|
Deserializer< T > |
deserializer |
|
) |
| |
|
inline |
Registers a deserializer for type T and an exact media type.
- Parameters
-
| type_name | Wire tag identifying T in serialized chunks. Tags a format already describes (json, object, string, ...) are not written; the media type alone says as much. |
| mimetype | Exact media type accepted by deserializer. |
| deserializer | Callable reconstructing a T from a Chunk. |
- Returns
- OK on success, or an error (e.g. when
deserializer is empty).
◆ RegisterSerializer()
template<typename T >
| absl::Status a11::data::SerializationRegistry::RegisterSerializer |
( |
std::string |
type_name, |
|
|
const std::string & |
mimetype, |
|
|
Serializer< T > |
serializer |
|
) |
| |
|
inline |
Registers a serializer for type T and an exact media type.
- Parameters
-
| type_name | Wire tag identifying T in serialized chunks. Tags a format already describes (json, object, string, ...) are not written; the media type alone says as much. |
| mimetype | Exact media type produced by serializer. |
| serializer | Callable converting a T to a Chunk. |
- Returns
- OK on success, or an error (e.g. when
serializer is empty).
◆ serializer_count()
| size_t a11::data::SerializationRegistry::serializer_count |
( |
| ) |
const |
Number of registered serializers.
◆ ToChunk()
template<typename T >
| absl::StatusOr< Chunk > a11::data::SerializationRegistry::ToChunk |
( |
const T & |
value, |
|
|
std::string_view |
mimetype = {} |
|
) |
| const |
|
inline |
Serializes value into a Chunk.
- Parameters
-
| value | Value to serialize. |
| mimetype | Optional media type to select a representation; when empty the type's registered default (by registration order) is used. |
- Returns
- A chunk with an exact mimetype and type tag, or an error when no matching serializer is registered.
The documentation for this class was generated from the following files: