xronos-sdk 0.14.0
Xronos C++ SDK
Loading...
Searching...
No Matches
xronos::sdk::IsSerializer Concept Reference

Constraints for a serializer that can be used on ports. More...

#include <xronos/sdk/port.hh>

Concept definition

template<class S, class T>
concept IsSerializer = requires(S serializer, const T& value, std::span<const std::byte> data) {
{ serializer.serialize(value) } -> std::same_as<std::vector<std::byte>>;
{ serializer.deserialize(data) } -> std::same_as<T>;
{ S::encoding } -> std::convertible_to<std::string_view>;
}
Constraints for a serializer that can be used on ports.
Definition port.hh:113

Detailed Description

Constraints for a serializer that can be used on ports.

S must convert values of type T to bytes and back, and name the byte layout it produces in a static encoding member. Conversions are written as calls on a serializer object. This allows conversions to be implemented either as methods or static member functions, and allows a serializer to carry configuration.

The encoding name is part of what an exported port declares, and two exported ports connect only when their encoding names are equal. It must therefore identify the layout precisely enough that any two serializers sharing a name are interchangeable, and must be a non-empty compile-time constant.

A port names its serializer as a class template, so the constraint applies to Serializer<T>.

Template Parameters
SThe serializer type.
TThe value type it converts.