Go to the documentation of this file.
9 #ifndef EAGINE_MESSAGE_BUS_SERIALIZE_HPP
10 #define EAGINE_MESSAGE_BUS_SERIALIZE_HPP
12 #include "../extract.hpp"
13 #include "../message_id.hpp"
14 #include "../serialize/block_sink.hpp"
15 #include "../serialize/block_source.hpp"
16 #include "../serialize/data_buffer.hpp"
17 #include "../serialize/packed_block_sink.hpp"
18 #include "../serialize/packed_block_source.hpp"
19 #include "../serialize/read.hpp"
20 #include "../serialize/string_backend.hpp"
21 #include "../serialize/write.hpp"
27 template <
identifier_t S
id,
typename Selector>
28 struct get_serialize_buffer_size<Sid,
message_id, Selector>
29 : get_serialize_buffer_size<Sid, message_id::base, Selector> {};
47 return serialize_buffer_for<default_serializer_backend::id_value>(inst);
54 template <
typename Backend>
60 std::is_base_of_v<serializer_backend, Backend>,
63 auto message_params = std::make_tuple(
71 msg.age_quarter_seconds,
74 return serialize(message_params, backend);
82 template <
typename Backend>
88 std::is_base_of_v<serializer_backend, Backend>,
94 if(
auto sink = backend.sink()) {
95 errors |=
extract(sink).write(msg.data);
108 template <
typename Backend>
115 std::is_base_of_v<deserializer_backend, Backend>,
118 auto message_params = std::tie(
126 msg.age_quarter_seconds,
137 template <
typename Backend>
144 std::is_base_of_v<deserializer_backend, Backend>,
150 if(
auto source{backend.source()}) {
151 msg.fetch_all_from(
extract(source));
164 template <
typename Backend>
170 std::is_base_of_v<deserializer_backend, Backend>,
178 msg_id = {class_id, method_id};
190 template <
typename T>
196 return {sink.
done(), errors};
205 template <
typename T>
213 return {sink.
done(), errors};
223 const auto value{msg_id.
id_tuple()};
234 template <
typename T>
240 return {source.remaining(), errors};
249 template <
typename T>
257 return {source.remaining(), errors};
267 std::tuple<identifier, identifier> value{};
275 template <
typename Backend,
typename Value>
277 stored_message::do_store_value(
const Value& value,
span_size_t max_size)
279 _buffer.resize(max_size);
281 Backend backend(sink);
284 set_serializer_id(backend.type_id());
285 _buffer.resize(sink.done().size());
291 template <
typename Value>
294 return do_store_value<default_serializer_backend>(value, max_size);
297 template <
typename Backend,
typename Value>
298 inline auto stored_message::do_fetch_value(Value& value) ->
bool {
300 Backend backend(source);
305 template <
typename Value>
307 return do_fetch_value<default_deserializer_backend>(value);
313 #endif // EAGINE_MESSAGE_BUS_SERIALIZE_HPP
Cross-platform implementation of deserializer backend using ASCII-only strings.
Definition: string_backend.hpp:206
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
Common code is placed in this namespace.
Definition: eagine.hpp:21
auto store_value(const Value &value, span_size_t max_size) -> bool
Serializes and stores the specified value (up to max_size).
Definition: serialize.hpp:293
auto fetch_value(Value &value) -> bool
Deserializes the stored content into the specified value.
Definition: serialize.hpp:306
static constexpr auto cover(T *addr, S size) noexcept -> span_if_mutable< T >
Creates a span starting at the specified pointer and specified length.
Definition: span.hpp:465
static constexpr auto extract(api_result_value< Result, api_result_validity::never > &) noexcept -> Result &
Overload of extract for api_result_value.
Definition: c_api_wrap.hpp:270
Primary template for conditionally valid values.
Definition: decl.hpp:49
Class for manipulating and testing a group of enumeration-based bits.
Definition: bitfield.hpp:19
Serialization data sink backed by a pre-allocated memory block.
Definition: block_sink.hpp:23
auto serialize_message(message_id msg_id, const message_view &msg, Backend &backend) -> std::enable_if_t< std::is_base_of_v< serializer_backend, Backend >, serialization_errors >
Serializes a bus message with the specified serializer backend.
Definition: serialize.hpp:83
static constexpr auto view(T *addr, S size) noexcept -> const_span< T >
Creates a view starting at the specified pointer and specified length.
Definition: span.hpp:458
Unpacking deserialization data source backed by a pre-allocated memory block.
Definition: packed_block_source.hpp:21
auto done() const noexcept -> memory::block
Returns the part of the backing block already written to.
Definition: block_sink.hpp:43
Deserialization data source backed by a pre-allocated memory block.
Definition: block_source.hpp:23
auto default_serialize_packed(T &value, memory::block blk, data_compressor compressor) -> serialization_result< memory::const_block >
Uses backend and compressor to serialize and pack a value into a memory block.
Definition: serialize.hpp:206
auto serialize_message_header(message_id msg_id, const message_view &msg, Backend &backend) -> std::enable_if_t< std::is_base_of_v< serializer_backend, Backend >, serialization_errors >
Serializes a bus message header with the specified serializer backend.
Definition: serialize.hpp:55
auto deserialize(T &value, Backend &backend) -> std::enable_if_t< std::is_base_of_v< deserializer_backend, Backend >, deserialization_errors >
Deserializes a value with the specified serialization backend.
Definition: read.hpp:475
auto default_deserialize_packed(T &value, memory::const_block blk, data_compressor compressor) -> deserialization_result< memory::const_block >
Uses backend and compressor to deserialize and unpack a value from a block.
Definition: serialize.hpp:250
Combines message information and a non-owning view to message content.
Definition: message.hpp:288
Non-owning view of a contiguous range of memory with ValueType elements.
Definition: flatten_fwd.hpp:16
auto serialize(T &value, Backend &backend) -> std::enable_if_t< std::is_base_of_v< serializer_backend, Backend >, serialization_errors >
Serializes a value with the specified serialization backend.
Definition: write.hpp:480
auto deserialize_message_header(identifier &class_id, identifier &method_id, stored_message &msg, Backend &backend) -> std::enable_if_t< std::is_base_of_v< deserializer_backend, Backend >, deserialization_errors >
Deserializes a bus message header with the specified deserializer backend.
Definition: serialize.hpp:109
Packing serialization data sink backed by a pre-allocated memory block.
Definition: packed_block_sink.hpp:21
constexpr auto id_tuple() const noexcept -> std::tuple< identifier, identifier >
Returns the class and method identifiers in a tuple. See class_ See method.
Definition: message_id.hpp:78
auto default_serialize_message_type(message_id msg_id, memory::block blk)
Default-serializes the specified message id into a memory block.
Definition: serialize.hpp:222
auto default_serialize(T &value, memory::block blk) -> serialization_result< memory::const_block >
Uses the default backend to serialize a value into a memory block.
Definition: serialize.hpp:191
auto default_deserialize(T &value, memory::const_block blk) -> deserialization_result< memory::const_block >
Uses the default backend to deserialize a value from a memory block.
Definition: serialize.hpp:235
Class implementing data compression and decompresson.
Definition: compression.hpp:37
auto deserialize_message(identifier &class_id, identifier &method_id, stored_message &msg, Backend &backend) -> std::enable_if_t< std::is_base_of_v< deserializer_backend, Backend >, deserialization_errors >
Deserializes a bus message with the specified deserializer backend.
Definition: serialize.hpp:138
auto default_serialize_buffer_for(const T &inst)
Returns a suitable buffer for the serialization of the specified object.
Definition: serialize.hpp:46
Cross-platform implementation of serializer backend using ASCII-only strings.
Definition: string_backend.hpp:26
Basic template for limited length, packed string identifiers.
Definition: identifier.hpp:178
@ backend_error
Internal error in the serialization backend.
Class storing two identifier values representing class/method pair.
Definition: message_id.hpp:25
@ backend_error
Internal error in the deserialization backend.
Combines message information and an owned message content buffer.
Definition: message.hpp:316
auto default_deserialize_message_type(message_id &msg_id, memory::const_block blk)
Default-deserializes the specified message id from a memory block.
Definition: serialize.hpp:266
@ message_id
The message type id has been verified.