class final
#include <core/reflection/type_server.hpp>
TypeServer Used to setup a TypeChannel on top of a stream, from the server side.
This class allows the server to send and receive values of types unknown by the client to the client. Not all types registered on the server will support this: some may not have enough information to be serialized. The set of types which can be safely serialized is returned by the connect function.
The protocol used by this class is as follows:
- Server receives a list of supported trait types from the client, and whether they are structural.
- Server receives a list of the types which the client already knows.
- Server sends the type information of the types which the client does not know. This includes: a) name of each type, b) structural trait of the type which is supported by the client, if any, b) non-structural traits of the type which are supported by the client, d) if the type has a structural trait and is default-constructible, the default-constructed serialized value.
If the type has multiple structural traits, the first one added to the server is used. The non-structural traits are sent in the order they were added to the server.
Public types
-
using Serialize = memory::
Function<bool(data:: Serializer&, const Type&, bool) const > - Function type for serializing traits.
-
using DiscoverTypes = void(*)(const Type&, memory::
Function<void(const Type&) const >&) - Function type for discovering new types from a trait.
Constructors, destructors, conversion operators
- TypeServer()
- Default constructs.
Public functions
- void addTrait(const Type& traitType, Serialize serialize, DiscoverTypes discoverTypes)
- Registers a trait to be supported by the channel.
-
template<typename T>void addTrait(Serialize serialize, DiscoverTypes discoverTypes)
- Registers a trait to be supported by the channel.
- void addType(const Type& type)
- Adds a type to be supported by the channel.
-
template<typename T>void addType()
- Adds a type to be supported by the channel.
-
auto connect(memory::
Stream& stream) -> memory:: Opt<Connection> - Connects to a new client, using the given stream.
Typedef documentation
using cubos:: core:: reflection:: TypeServer:: Serialize = memory:: Function<bool(data:: Serializer&, const Type&, bool) const >
Function type for serializing traits.
Receives a serializer, the value to serialize, and whether the type is already serializable.
Function documentation
void cubos:: core:: reflection:: TypeServer:: addTrait(const Type& traitType,
Serialize serialize,
DiscoverTypes discoverTypes)
Registers a trait to be supported by the channel.
Parameters | |
---|---|
traitType | |
serialize | Function to serialize the trait. |
discoverTypes | Function to discover new types from the trait. |
template<typename T>
void cubos:: core:: reflection:: TypeServer:: addTrait(Serialize serialize,
DiscoverTypes discoverTypes)
Registers a trait to be supported by the channel.
Template parameters | |
---|---|
T | Trait type. |
Parameters | |
serialize | Function to serialize the trait. |
discoverTypes | Function to discover new types from the trait. |
void cubos:: core:: reflection:: TypeServer:: addType(const Type& type)
Adds a type to be supported by the channel.
Parameters | |
---|---|
type | Type to be supported. |
Also adds any types used by the type, recursively. I.e., types of fields if the type has a FieldsTrait.
template<typename T>
void cubos:: core:: reflection:: TypeServer:: addType()
Adds a type to be supported by the channel.
Template parameters | |
---|---|
T | Type to be supported. |
Also adds any types used by the type, recursively. I.e., types of fields if the type has a FieldsTrait.
memory:: Opt<Connection> cubos:: core:: reflection:: TypeServer:: connect(memory:: Stream& stream)
Connects to a new client, using the given stream.
Parameters | |
---|---|
stream | Stream. |
Returns | Connection information, or nothing if the connection failed. |