OpenEnroth 73e68f7
|
#include <BinaryConcepts.h>
Binary serialization provides a set of overloads, and when there's too many, a moment comes when they need to be explicitly ordered. Consider the following overloads:
And the following call:
This call is ambiguous because the types provided match both overloads, with neither one being a better match. Besides, the ambiguity is genuine here - the order really doesn't matter, so whether #1
calls into #2
or the other way around, result stays the same. However, this is C++, so we need to:
In this particular case it makes sense to disambiguate on src
and dst
first, and then process all the tags. How to do it? We can introduce the notion of 'proxy' binary serialization types:
src
with another type and forwards to another deserialize
overload.dst
with another type and forwards to another serialize
overload.Thus, proxy types stand in contrast to regular, or "leaf" types - types for which non-template overloads are provided. All overloads that process tags require regular src
and dst
arguments, and this provides natural ordering:
src
/ dst
transformations are carried out.To achieve this, the following concepts are provided:
RegularBinarySource
to denote a non-proxy binary source (e.g., an InputStream
).RegularBinarySink
to denote a non-proxy binary sink (e.g., an OutputStream
).RegularBinarizable
to denote a non-proxy client type to be serialized or deserialized.Then, for the types that actually are proxies, the following type traits are provided for specialization:
is_proxy_binary_source
for proxy binary sources.is_proxy_binary_sink
for proxy binary sinks.is_proxy_binarizable
for proxy client types.