|
A11 (C++ runtime)
Native C++ implementation of the A11 action and streaming runtime
|
A registry of serializers and deserializers indexed by type and MIME. More...
#include <cpp/a11/data/serialization.h>
Classes | |
| struct | DeserializerRegistration |
| struct | Impl |
| struct | SerializerRegistration |
Public Types | |
| 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. | |
Public Member Functions | |
| SerializationRegistry (bool register_defaults=false) | |
| Constructs a registry. | |
| ~SerializationRegistry () | |
| SerializationRegistry (const SerializationRegistry &)=delete | |
| SerializationRegistry & | operator= (const SerializationRegistry &)=delete |
| template<typename T > | |
| absl::Status | RegisterSerializer (std::string type_name, std::string mimetype, Serializer< T > serializer) |
Registers a serializer for type T and an exact media type. | |
| template<typename T > | |
| absl::Status | RegisterDeserializer (std::string type_name, std::string mimetype, Deserializer< T > deserializer) |
Registers a deserializer for type T and an exact media type. | |
| template<typename T > | |
| absl::Status | Register (std::string type_name, std::string mimetype, Serializer< T > serializer, Deserializer< T > deserializer) |
Atomically registers a serializer/deserializer pair for T. | |
| template<typename T > | |
| absl::StatusOr< Chunk > | ToChunk (const T &value, std::string_view mimetype={}) const |
Serializes value into a Chunk. | |
| template<typename T > | |
| absl::StatusOr< T > | FromChunk (const Chunk &chunk, const std::vector< std::string > &mimetype_patterns={}) const |
Deserializes chunk into a value of type T. | |
| absl::Status | RegisterDefaults () |
| Installs the standard JSON and MessagePack codecs. | |
| size_t | serializer_count () const |
| Number of registered serializers. | |
| size_t | deserializer_count () const |
| Number of registered deserializers. | |
A registry of serializers and deserializers indexed by type and MIME.
Register a codec for a C++ type and an exact media type, then use ToChunk / FromChunk to convert values to and from a11::data::Chunk. A new registry is empty; pass register_defaults or call RegisterDefaults to install the standard JSON and MessagePack codecs. The process-wide registry from GlobalSerializationRegistry already has them. Not copyable.
| using a11::data::SerializationRegistry::Deserializer = std::function<absl::StatusOr<T>(const Chunk&)> |
Callable reconstructing a T from a Chunk.
| using a11::data::SerializationRegistry::Serializer = std::function<absl::StatusOr<Chunk>(const T&)> |
Callable turning a T into a Chunk.
Constructs a registry.
| register_defaults | When true, install the JSON and MessagePack codecs; otherwise start empty. |
| a11::data::SerializationRegistry::~SerializationRegistry | ( | ) |
|
delete |
| size_t a11::data::SerializationRegistry::deserializer_count | ( | ) | const |
Number of registered deserializers.
|
inline |
Deserializes chunk into a value of type T.
| 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. |
T.
|
delete |
|
inline |
Atomically registers a serializer/deserializer pair for T.
On failure to register the deserializer, the serializer added by this call is rolled back.
| type_name | Wire tag identifying T in serialized chunks. |
| mimetype | Exact media type for both codecs. |
| serializer | Callable converting a T to a Chunk. |
| deserializer | Callable reconstructing a T from a Chunk. |
| absl::Status a11::data::SerializationRegistry::RegisterDefaults | ( | ) |
Installs the standard JSON and MessagePack codecs.
|
inline |
Registers a deserializer for type T and an exact media type.
| type_name | Wire tag identifying T in serialized chunks. |
| mimetype | Exact media type accepted by deserializer. |
| deserializer | Callable reconstructing a T from a Chunk. |
deserializer is empty).
|
inline |
Registers a serializer for type T and an exact media type.
| type_name | Wire tag identifying T in serialized chunks. |
| mimetype | Exact media type produced by serializer. |
| serializer | Callable converting a T to a Chunk. |
serializer is empty). | size_t a11::data::SerializationRegistry::serializer_count | ( | ) | const |
Number of registered serializers.
|
inline |
Serializes value into a Chunk.
| value | Value to serialize. |
| mimetype | Optional media type to select a representation; when empty the type's registered default (by registration order) is used. |