sbepp
provides a way to access nearly all information provided by XML schema and other useful properties via traits mechanism.
Tags
To access a trait you need a schema entity's tag. Tag is basically a path to an entity. The tag for a schema itself (for sbepp::schema_traits
) is <schema_name>::schema
. Tags for messages have form <schema_name>::schema::messages::<msg_name>
and tags for types <schema_name>::schema::types::<type_name>
. Here's an example:
<?xml version="1.0" encoding="UTF-8"?>
<sbe:messageSchema package="schema_name">
<types>
<type name="uint32_req" primitiveType="uint32"/>
<enum name="numbers" encodingType="uint8">
<validValue name="One">1</validValue>
<validValue name="Two">2</validValue>
</enum>
<set name="options" encodingType="uint8">
<choice name="A">0</choice>
<choice name="B">2</choice>
</set>
<composite name="groupSizeEncoding">
<type name="blockLength" primitiveType="uint16"/>
<type name="numInGroup" primitiveType="uint16"/>
</composite>
</types>
<sbe:message name="msg" id="1">
<field name="field" id="1" type="uint32"/>
<group name="group" id="2">
<field name="field" id="1" type="uint32"/>
</group>
<data name="data" id="3" type="varDataEncoding"/>
</sbe:message>
</sbe:messageSchema>
For built-in types like sbepp::char_t
, the type itself works as a tag, e.g.
static constexpr primitive_type max_value() noexcept
Returns maxValue. Available only if length() == 1 and presence() != field_presence::constant
Implementation-wise, each tag is an empty struct
, it's possible to test tag kind using sbepp::is_message_tag
and similar helpers.
- See also
- Tag-based accessors
-
sbepp::traits_tag
Using traits
Similar to std::numeric_limits
, sbepp
traits are accessed like trait_name<Tag>::value()
:
schema_name::schema::types::optional>::null_value();
static constexpr version_t version() noexcept
Returns version attribute.
Provides various traits and attributes of a <type> element.
Definition sbepp.hpp:4043
For the list of available traits see Traits list.
Note that there's no such thing as sbepp::ref_traits
because <ref>
fields always refer to another type. To access their properties, use traits corresponding to the referred type (e.g. sbepp::set_traits
if <ref>
refers to a <set>
).