sbepp
Loading...
Searching...
No Matches
sbepp Namespace Reference

The main sbepp namespace. More...

Namespaces

namespace  cursor_ops
 Contains cursor wrappers which allow more precise control over its position.
 
namespace  detail
 Namespace for various implementation details. Should not be used directly.
 

Classes

struct  byte_type
 Trait to get view's byte type. More...
 
class  char_opt_t
 Built-in char optional type. More...
 
class  char_t
 Built-in char required type. More...
 
class  composite_traits
 Provides various traits/attributes of a <composite> element. More...
 
class  cursor
 Represents cursor which is used in cursor-based API. Clients should not use undocumented methods. More...
 
class  data_traits
 Provides various traits/attributes of a <data> element. More...
 
struct  default_init_t
 tag for dynamic_array_ref::resize(). Used to skip value initialization. More...
 
class  double_opt_t
 Built-in double optional type. More...
 
class  double_t
 Built-in double required type. More...
 
class  enum_traits
 Provides various traits/attributes of an <enum> element. More...
 
class  enum_value_traits
 Provides various traits/attributes of a <validValue> element. More...
 
class  field_traits
 Provides various traits/attributes of a <field> element. More...
 
class  float_opt_t
 Built-in float optional type. More...
 
class  float_t
 Built-in float required type. More...
 
class  group_traits
 Provides various traits/attributes of a <group> element. More...
 
class  int16_opt_t
 Built-in int16 optional type. More...
 
class  int16_t
 Built-in int16 required type. More...
 
class  int32_opt_t
 Built-in int32 optional type. More...
 
class  int32_t
 Built-in int32 required type. More...
 
class  int64_opt_t
 Built-in int64 optional type. More...
 
class  int64_t
 Built-in int64 required type. More...
 
class  int8_opt_t
 Built-in int8 optional type. More...
 
class  int8_t
 Built-in int8 required type. More...
 
struct  is_enum
 Checks if T is an enumeration. More...
 
class  message_traits
 Provides various traits/attributes of a <message> element. More...
 
struct  nullopt_t
 Tag type used to initialize optional types with null value. More...
 
class  schema_traits
 Provides various traits/attributes of a <messageSchema> element. More...
 
class  set_choice_traits
 Provides various traits/attributes of a <choice> element. More...
 
class  set_traits
 Provides various traits/attributes of a <set> element. More...
 
struct  size_bytes_checked_result
 Result type of size_bytes_checked More...
 
struct  traits_tag
 Maps representation type to its tag. More...
 
class  type_traits
 Provides various traits and attributes of a <type> element. More...
 
class  uint16_opt_t
 Built-in uint16 optional type. More...
 
class  uint16_t
 Built-in uint16 required type. More...
 
class  uint32_opt_t
 Built-in uint32 optional type. More...
 
class  uint32_t
 Built-in uint32 required type. More...
 
class  uint64_opt_t
 Built-in uint64 optional type. More...
 
class  uint64_t
 Built-in uint64 required type. More...
 
class  uint8_opt_t
 Built-in uint8 optional type. More...
 
class  uint8_t
 Built-in uint8 required type. More...
 
struct  unknown_enum_value_tag
 Tag for unknown enum values. More...
 

Concepts

concept  array_type
 Concept for sbepp::is_array_type<T>::value
 
concept  required_type
 Concept for sbepp::is_required_type<T>::value
 
concept  optional_type
 Concept for sbepp::is_optional_type<T>::value
 
concept  non_array_type
 Concept for sbepp::is_non_array_type<T>::value
 
concept  type
 Concept for sbepp::is_type<T>::value
 
concept  enumeration
 Concept for sbepp::is_enum<T>::value
 
concept  set
 Concept for sbepp::is_set<T>::value
 
concept  composite
 Concept for sbepp::is_composite<T>::value
 
concept  message
 Concept for sbepp::is_message<T>::value
 
concept  flat_group
 Concept for sbepp::is_flat_group<T>::value
 
concept  nested_group
 Concept for sbepp::is_nested_group<T>::value
 
concept  group
 Concept for sbepp::is_group<T>::value
 
concept  data
 Concept for sbepp::is_data<T>::value
 

Typedefs

using length_t = std::uint64_t
 Represents type_traits::length() value type.
 
using offset_t = std::uint64_t
 Represents offset trait value type, e.g. type_traits::offset()
 
using version_t = std::uint64_t
 Represents version trait value type, e.g. type_traits::since_version()
 
using schema_id_t = std::uint32_t
 Represents schema_traits::id() value type.
 
using message_id_t = std::uint32_t
 Represents message_traits::id() value type.
 
using block_length_t = std::uint64_t
 Represents block_length trait value type, e.g. message_traits::block_length()
 
using member_id_t = std::uint16_t
 Represents id trait value type, e.g. field_traits::id()
 
using choice_index_t = std::uint8_t
 Represents set_choice_traits::index() value type.
 
template<typename View >
using byte_type_t = typename byte_type<View>::type
 Shortcut for byte_type<T>::type
 
template<typename ValueType >
using traits_tag_t = typename traits_tag<ValueType>::type
 Shorthand for sbepp::traits_tag<T>::type
 
template<typename T >
using is_array_type = typename detail::is_array_type_impl<T>::type
 Checks is T is an array type.
 
template<typename T >
using is_required_type = detail::is_base_of_tmp<detail::required_base, T>
 Checks if T is a non-array required type.
 
template<typename T >
using is_optional_type = detail::is_base_of_tmp<detail::optional_base, T>
 Checks if T is a non-array optional type.
 
template<typename T >
using is_non_array_type
 Checks if T is a non-array type.
 
template<typename T >
using is_type
 Checks if T is a type of any kind.
 
template<typename T >
using is_set = detail::is_base_of_tmp<detail::bitset_base, T>
 Checks if T is a set.
 
template<typename T >
using is_composite = detail::is_base_of_tmp<detail::composite_base, T>
 Checks if T is a composite.
 
template<typename T >
using is_message = detail::is_base_of_tmp<detail::message_base, T>
 Checks if T is a message.
 
template<typename T >
using is_flat_group = detail::is_base_of_tmp<detail::flat_group_base, T>
 Checks if T is a flat group.
 
template<typename T >
using is_nested_group = detail::is_base_of_tmp<detail::nested_group_base, T>
 Checks if T is a nested group.
 
template<typename T >
using is_group
 Checks if T is a group of any kind.
 
template<typename T >
using is_group_entry = detail::is_base_of_tmp<detail::entry_base, T>
 Checks if T is a group entry.
 
template<typename T >
using is_data = typename detail::is_data_impl<T>::type
 Checks if T is a data.
 

Enumerations

enum class  field_presence { required , optional , constant }
 Represents presence trait value type, e.g. type_traits::presence() More...
 
enum class  endian { little , big , native }
 Represents schema_traits::byte_order() value type. When SBEPP_HAS_ENDIAN is 1, it's just an alias to std::endian. Requires SBEPP_BYTE_ORDER to be defined if endianness is not detected automatically. More...
 
enum class  eos_null { none , single , all }
 Represents number of null bytes that can be added after the end-of-string by detail::static_array_ref::assign_string() More...
 

Functions

void assertion_failed (char const *expr, char const *function, char const *file, long line)
 When SBEPP_ASSERT_HANDLER or SBEPP_ENABLE_ASSERTS_WITH_HANDLER is defined, this function is called for failed assertions. Must be defined by the client.
 
template<typename T >
constexpr std::size_t size_bytes (T v) noexcept
 Returns the size of the underlying data represented by message/group/entry/data/composite view, including headers.
 
template<typename T , typename Byte >
constexpr std::size_t size_bytes (T v, cursor< Byte > c) noexcept
 Similar to sbepp::size_bytes but has constant complexity because it expects c to be set at the end of v. Useful to read the whole message and then get its size in constant time. Not applicable to composites.
 
template<typename T >
constexpr auto get_header (T v) noexcept -> decltype(v(detail::get_header_tag{}))
 Returns the header of a message/group.
 
template<typename T >
constexpr auto addressof (T v) noexcept -> decltype(v(detail::addressof_tag{}))
 Returns pointer to the underlying data referenced by a view.
 
template<typename Enum >
constexpr std::underlying_type< Enum >::type to_underlying (Enum e) noexcept
 Converts an enumeration to its underlying type. Equivalent to C++23 std::to_underlying()
 
template<typename View >
constexpr cursor< byte_type_t< View > > init_cursor (View view) noexcept
 Initializes cursor from a message/group view with the same byte type.
 
template<typename View >
constexpr cursor< typename std::add_const< byte_type_t< View > >::type > init_const_cursor (View view) noexcept
 Initializes cursor from a message/group view with const byte type.
 
template<typename Message >
constexpr auto fill_message_header (Message m) noexcept -> decltype(m(detail::fill_message_header_tag{}))
 Fill message header.
 
template<typename Group , typename Size >
constexpr auto fill_group_header (Group g, Size num_in_group) noexcept -> decltype(g(detail::fill_group_header_tag{}, num_in_group))
 Fill group header.
 
template<template< typename > class View, typename Byte >
constexpr View< Byte > make_view (Byte *ptr, const std::size_t size) noexcept
 Construct view from memory buffer.
 
template<template< typename > class View, typename Byte >
constexpr View< typename std::add_const< Byte >::type > make_const_view (Byte *ptr, const std::size_t size) noexcept
 Construct read-only view from memory buffer.
 
template<typename Visitor , typename View , typename Cursor , typename = detail::enable_if_t<detail::is_visitable_view<View>::value>>
constexpr Visitor && visit (View view, Cursor &c, Visitor &&visitor={})
 Visit a view using given cursor.
 
template<typename Visitor , typename View , typename = detail::enable_if_t<detail::is_visitable_view<View>::value>>
constexpr Visitor && visit (View view, Visitor &&visitor={})
 Visits a view.
 
template<typename Visitor , typename Set >
constexpr Visitor && visit (Set s, Visitor &&visitor={})
 Visits set choices.
 
template<typename Visitor , typename Enum >
constexpr Visitor && visit (Enum e, Visitor &&visitor={})
 Visits enum value.
 
template<typename Visitor , typename View , typename Cursor , typename = detail::enable_if_t<detail::is_visitable_view<View>::value>>
constexpr Visitor && visit_children (View view, Cursor &c, Visitor &&visitor={})
 Visit view's children using provided cursor.
 
template<typename Visitor , typename View , typename = detail::enable_if_t<detail::is_visitable_view<View>::value>>
constexpr Visitor && visit_children (View view, Visitor &&visitor={})
 Visit view's children.
 
template<typename E , typename = detail::enable_if_t<is_enum<E>::value>>
constexpr const char * enum_to_string (const E e) noexcept
 Converts enum to string.
 
template<typename Set , typename Visitor >
constexpr auto visit_set (const Set s, Visitor &&visitor) noexcept -> decltype(s(detail::visit_set_tag{}, std::forward< Visitor >(visitor)))
 Visits set choices in order of their declaration.
 
template<typename View >
constexpr size_bytes_checked_result size_bytes_checked (View view, std::size_t size) noexcept
 Calculate view size with additional safety checks.
 

Variables

constexpr default_init_t default_init {}
 helper to pass default_init_t to dynamic_array_ref::resize().
 
constexpr nullopt_t nullopt {0}
 Helper constant used to initialize optional types with null value.
 
template<typename T >
constexpr auto is_array_type_v = is_array_type<T>::value
 Shorthand for sbepp::is_array_type<T>::value
 
template<typename T >
constexpr auto is_required_type_v = is_required_type<T>::value
 Shorthand for sbepp::is_required_type<T>::value
 
template<typename T >
constexpr auto is_optional_type_v = is_optional_type<T>::value
 Shorthand for sbepp::is_optional_type<T>::value
 
template<typename T >
constexpr auto is_non_array_type_v = is_non_array_type<T>::value
 Shorthand for sbepp::is_non_array_type<T>::value
 
template<typename T >
constexpr auto is_type_v = is_type<T>::value
 Shorthand for sbepp::is_type<T>::value
 
template<typename T >
constexpr auto is_enum_v = is_enum<T>::value
 Shorthand for sbepp::is_enum<T>::value
 
template<typename T >
constexpr auto is_set_v = is_set<T>::value
 Shorthand for sbepp::is_set<T>::value
 
template<typename T >
constexpr auto is_composite_v = is_composite<T>::value
 Shorthand for sbepp::is_composite<T>::value
 
template<typename T >
constexpr auto is_message_v = is_message<T>::value
 Shorthand for sbepp::is_message<T>::value
 
template<typename T >
constexpr auto is_flat_group_v = is_flat_group<T>::value
 Shorthand for sbepp::is_flat_group<T>::value
 
template<typename T >
constexpr auto is_nested_group_v = is_nested_group<T>::value
 Shorthand for sbepp::is_nested_group<T>::value
 
template<typename T >
constexpr auto is_group_v = is_group<T>::value
 Shorthand for sbepp::is_group<T>::value
 
template<typename T >
constexpr auto is_data_v = is_data<T>::value
 Shorthand for sbepp::is_data<T>::value
 

Detailed Description

The main sbepp namespace.

Enumeration Type Documentation

◆ endian

enum class sbepp::endian
strong

Represents schema_traits::byte_order() value type. When SBEPP_HAS_ENDIAN is 1, it's just an alias to std::endian. Requires SBEPP_BYTE_ORDER to be defined if endianness is not detected automatically.

Enumerator
little 

little-endian

big 

big-endian

native 

current platform endianness

◆ eos_null

enum class sbepp::eos_null
strong

Represents number of null bytes that can be added after the end-of-string by detail::static_array_ref::assign_string()

Enumerator
none 

Bytes after the last string character will not be touched. Useful when underlying buffer is zero-filled.

single 

Single byte after the last string character will be set to null. Useful when decoder will look for the first null byte to calculate string length.

all 

All bytes after the last string character will be set to null.

◆ field_presence

enum class sbepp::field_presence
strong

Represents presence trait value type, e.g. type_traits::presence()

Enumerator
required 

field is required

optional 

field is optional

constant 

field is constant

Function Documentation

◆ addressof()

template<typename T >
constexpr auto sbepp::addressof ( T v) -> decltype(v(detail::addressof_tag{}))
constexprnoexcept

Returns pointer to the underlying data referenced by a view.

Parameters
vview
Returns
pointer to the underlying data

◆ assertion_failed()

void sbepp::assertion_failed ( char const * expr,
char const * function,
char const * file,
long line )

When SBEPP_ASSERT_HANDLER or SBEPP_ENABLE_ASSERTS_WITH_HANDLER is defined, this function is called for failed assertions. Must be defined by the client.

Parameters
exprexpression that failed
functionenclosing function name
filefile name
lineline number

◆ enum_to_string()

template<typename E , typename = detail::enable_if_t<is_enum<E>::value>>
constexpr const char * sbepp::enum_to_string ( const E e)
constexprnoexcept

Converts enum to string.

Parameters
eenum to convert
Returns
pointer to a null-terminated string representing an enumerator's name or nullptr if e holds unknown value
Deprecated
Deprecated in favor of sbepp::visit, will be removed in the next major update.

◆ fill_group_header()

template<typename Group , typename Size >
constexpr auto sbepp::fill_group_header ( Group g,
Size num_in_group ) -> decltype(g(detail::fill_group_header_tag{}, num_in_group))
constexprnoexcept

Fill group header.

Automatically fills these fields in group header:

  • blockLength
  • numInGroup
  • numGroups (if exists in header)
  • numVarDataFields (if exists in header)
Parameters
ggroup
num_in_groupnumber if entries in group
Returns
group header

◆ fill_message_header()

template<typename Message >
constexpr auto sbepp::fill_message_header ( Message m) -> decltype(m(detail::fill_message_header_tag{}))
constexprnoexcept

Fill message header.

Automatically fills these fields in message header:

  • schemaId
  • templateId
  • version
  • blockLength
  • numGroups (if exists in header)
  • numVarDataFields (if exists in header)
Parameters
mmessage
Returns
message header

◆ get_header()

template<typename T >
constexpr auto sbepp::get_header ( T v) -> decltype(v(detail::get_header_tag{}))
constexprnoexcept

Returns the header of a message/group.

Parameters
vmessage/group view
Returns
header composite view

◆ init_const_cursor()

template<typename View >
constexpr cursor< typename std::add_const< byte_type_t< View > >::type > sbepp::init_const_cursor ( View view)
constexprnoexcept

Initializes cursor from a message/group view with const byte type.

Example:

schema::messages::msg1<char> {ptr, size};
auto value = m.field(c);
m.field(1, c); // error: cursor has const-qualified byte type
constexpr cursor< typename std::add_const< byte_type_t< View > >::type > init_const_cursor(View view) noexcept
Initializes cursor from a message/group view with const byte type.
Definition sbepp.hpp:2869
Parameters
viewmessage or group view
Returns
initialized cursor

◆ init_cursor()

template<typename View >
constexpr cursor< byte_type_t< View > > sbepp::init_cursor ( View view)
constexprnoexcept

Initializes cursor from a message/group view with the same byte type.

Example:

schema::messages::msg1<char> {ptr, size};
auto c = sbepp::init_cursor(m);
auto value = m.field(c);
constexpr cursor< byte_type_t< View > > init_cursor(View view) noexcept
Initializes cursor from a message/group view with the same byte type.
Definition sbepp.hpp:2846
Parameters
viewmessage or group view
Returns
initialized cursor

◆ make_const_view()

template<template< typename > class View, typename Byte >
constexpr View< typename std::add_const< Byte >::type > sbepp::make_const_view ( Byte * ptr,
const std::size_t size )
constexprnoexcept

Construct read-only view from memory buffer.

View's byte type will be a const-qualified buffer byte type. Example:

std::array<char, N> buf;
// creates some_schema::messages::msg1<const char>
auto m = sbepp::make_view<some_schema::messages::msg1>(
buf.data(), buf.size());
Template Parameters
Viewview template
Bytebyte type
Parameters
ptrbuffer start
sizebuffer size
Returns
constructed view

◆ make_view()

template<template< typename > class View, typename Byte >
constexpr View< Byte > sbepp::make_view ( Byte * ptr,
const std::size_t size )
constexprnoexcept

Construct view from memory buffer.

View will have the same byte type as provided buffer. Example:

std::array<char, N> buf;
auto m = sbepp::make_view<some_schema::messages::msg1>(
buf.data(), buf.size()); // creates some_schema::messages::msg1<char>
Template Parameters
Viewview template
Bytebyte type
Parameters
ptrbuffer start
sizebuffer size
Returns
constructed view

◆ size_bytes() [1/2]

template<typename T >
constexpr std::size_t sbepp::size_bytes ( T v)
constexprnoexcept

Returns the size of the underlying data represented by message/group/entry/data/composite view, including headers.

In general case, for message/group/entry, the complexity is O(a^n) where n is the depth of the level. For composites and data it's O(1).

Parameters
vview object
Returns
size in bytes

◆ size_bytes() [2/2]

template<typename T , typename Byte >
constexpr std::size_t sbepp::size_bytes ( T v,
cursor< Byte > c )
constexprnoexcept

Similar to sbepp::size_bytes but has constant complexity because it expects c to be set at the end of v. Useful to read the whole message and then get its size in constant time. Not applicable to composites.

Parameters
vview object
ccursor
Returns
size in bytes

◆ size_bytes_checked()

template<typename View >
constexpr size_bytes_checked_result sbepp::size_bytes_checked ( View view,
std::size_t size )
constexprnoexcept

Calculate view size with additional safety checks.

Similar to size_bytes() but stops if view cannot fit into the given size. Useful to check that incoming message is fully contained within given buffer.

Parameters
viewmessage or group view
sizebuffer size

◆ to_underlying()

template<typename Enum >
constexpr std::underlying_type< Enum >::type sbepp::to_underlying ( Enum e)
constexprnoexcept

Converts an enumeration to its underlying type. Equivalent to C++23 std::to_underlying()

Parameters
eenumerator
Returns
enumerator's underlying value

◆ visit() [1/4]

template<typename Visitor , typename Enum >
constexpr Visitor && sbepp::visit ( Enum e,
Visitor && visitor = {} )
constexpr

Visits enum value.

Template Parameters
Visitorvisitor type
Parameters
eenum value to visit
visitorvisitor instance, must have on_enum_value member function with the signature equivalent to void on_enum_value(Enum, EnumValueTag)
Returns
forwarded reference to visitor

If e is one of validValue-s from schema, calls visitor.on_enum_value(e, EnumValueTag{}) where EnumValueTag is a matched value's tag that can be passed to enum_value_traits. Otherwise, calls visitor.on_enum_value(e, sbepp::unknown_enum_value_tag{}).

See also
Visit API

◆ visit() [2/4]

template<typename Visitor , typename Set >
constexpr Visitor && sbepp::visit ( Set s,
Visitor && visitor = {} )
constexpr

Visits set choices.

Template Parameters
Visitorvisitor type
Parameters
sset to visit
visitorvisitor instance, must have on_set_choice member function with the signature equivalent to void on_set_choice(bool, ChoiceTag).
Returns
forwarded reference to visitor

Visits set choices in order of their schema declaration. For each choice calls visitor.on_set_choice(choice_value, ChoiceTag{}), where choice_value is the bool value of a choice and ChoiceTag is its tag that can be passed to set_choice_traits.

See also
Visit API

◆ visit() [3/4]

template<typename Visitor , typename View , typename Cursor , typename = detail::enable_if_t<detail::is_visitable_view<View>::value>>
constexpr Visitor && sbepp::visit ( View view,
Cursor & c,
Visitor && visitor = {} )
constexpr

Visit a view using given cursor.

Template Parameters
Visitorvisitor type
Parameters
viewmessage, group, entry or composite view
ccursor, passed as is to visitor
visitorvisitor
Returns
forwarded reference to visitor
See also
Visit API

◆ visit() [4/4]

template<typename Visitor , typename View , typename = detail::enable_if_t<detail::is_visitable_view<View>::value>>
constexpr Visitor && sbepp::visit ( View view,
Visitor && visitor = {} )
constexpr

Visits a view.

Template Parameters
Visitorvisitor type
Parameters
viewmessage, group, entry or composite view
visitorvisitor
Returns
forwarded reference to visitor
See also
Visit API

◆ visit_children() [1/2]

template<typename Visitor , typename View , typename Cursor , typename = detail::enable_if_t<detail::is_visitable_view<View>::value>>
constexpr Visitor && sbepp::visit_children ( View view,
Cursor & c,
Visitor && visitor = {} )
constexpr

Visit view's children using provided cursor.

Template Parameters
Visitorvisitor type
Parameters
viewmessage, group, entry or composite view
ccursor, ignored for composites, otherwise must point to the first view's child
visitorvisitor
Returns
forwarded reference to visitor
See also
Visit API

◆ visit_children() [2/2]

template<typename Visitor , typename View , typename = detail::enable_if_t<detail::is_visitable_view<View>::value>>
constexpr Visitor && sbepp::visit_children ( View view,
Visitor && visitor = {} )
constexpr

Visit view's children.

Template Parameters
Visitorvisitor type
Parameters
viewmessage, group, entry or composite view
visitorvisitor
Returns
forwarded reference to visitor
See also
Visit API

◆ visit_set()

template<typename Set , typename Visitor >
constexpr auto sbepp::visit_set ( const Set s,
Visitor && visitor ) -> decltype(s(detail::visit_set_tag{}, std::forward<Visitor>(visitor)))
constexprnoexcept

Visits set choices in order of their declaration.

Parameters
sset to visit
visitorvisitor. Must have signature void (bool choice_value, const char* choice_name)
Returns
forwarded reference to visitor
Deprecated
Deprecated in favor of sbepp::visit, will be removed in the next major update.

Variable Documentation

◆ default_init

constexpr default_init_t sbepp::default_init {}
inlineconstexpr

helper to pass default_init_t to dynamic_array_ref::resize().

Example: ref.resize(n, sbepp::default_init);.

◆ nullopt

constexpr nullopt_t sbepp::nullopt {0}
inlineconstexpr

Helper constant used to initialize optional types with null value.

Example: msg.optionalField(sbepp::nullopt);