sbepp
provides a way to access nearly all information provided by XML schema and other useful properties via traits mechanism.
Tags
To access any 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
Using traits
Similar to std::numeric_limits
, sbepp
traits are accessed like trait_name<Tag>::value()
:
static constexpr version_t version() noexcept
Returns version attribute.
static constexpr primitive_type null_value() noexcept
Returns nullValue. Available only if length() == 1 and presence() == field_presence::optional
For the list of available traits see Traits list.
- See also
sbepp::traits_tag