43template<
typename Message>
inline
44void checkBinaryLength(
const Message&, MessageSize length, MessageSize minimalRequiredLength)
46 if ONIXS_ILINK3_UNLIKELY(length < minimalRequiredLength)
47 throwBinaryBlockIsTooSmall(length, minimalRequiredLength, Message::className());
62template < class Container, class BlockLength >
68 return *
static_cast <const Container*
> (
this);
81 assert(container().blockLength() >= (offset + size<Value>()) &&
82 "The requested field exceeds provided block boundaries.");
84 const void*
const location = advanceByBytes(container().block(), offset);
85 return getValue<Value>(location);
97 return (null != value);
107 return (since <= container().version() &&
ordinary (value, offset, null ) );
114 typedef typename Enumeration::Base Base;
115 typedef typename Enumeration::Enum Enum;
124 typedef typename Enumeration::Base Base;
125 typedef typename Enumeration::Enum Enum;
128 return null != value;
153 return null != value;
163 return (since <= container().version() &&
decimal(value, offset, null));
170 assert(container().blockLength() >= (offset + Length) &&
"The requested field exceeds provided block boundaries.");
172 const Char*
const text =
reinterpret_cast <const Char*
> (advanceByBytes(container().block(), offset));
174 return StrRef(text, strnlen(text, Length));
185 return !value.empty();
203template <
class Container,
class BlockLength >
210 return *
static_cast<Container*
>(
this);
217 const BlockLength encodedBlockLength =
container().blockLength();
219 assert(encodedBlockLength >= offset);
221 const size_t paddingLength = encodedBlockLength - offset;
222 std::memset(advanceByBytes(
container().block(), offset), 0, paddingLength);
229 assert(
container().blockLength() >= (offset + size<FieldValue>()) &&
"The requested field exceeds provided block boundaries.");
231 void*
const fieldPos = advanceByBytes(
container().block(), offset);
232 setValue(fieldPos, value);
239 if ONIXS_ILINK3_UNLIKELY(since >
container().version())
240 throwDisallowedField();
249 typedef typename Enumeration::Base Base;
257 typedef typename Enumeration::Base Base;
258 setOrdinary(offset,
static_cast<Base
>(value), since);
265 assert(
container().blockLength() >= (offset + Size) &&
"The requested field exceeds provided block boundaries.");
266 assert(value.size() <= Size &&
"The string is truncated.");
268 void*
const fieldPos = advanceByBytes(
container().block(), offset);
269 const size_t sizeToCopy = (std::min)(Size,
static_cast<BlockLength
>(value.size()));
272 std::memcpy(fieldPos, value.data(), sizeToCopy);
274 std::memset(advanceByBytes(fieldPos, sizeToCopy), 0, Size - sizeToCopy);
281 if ONIXS_ILINK3_UNLIKELY(since >
container().version())
282 throwDisallowedField();
295template <class BodySizeType>
377template <
class EntryType,
class BlockLength,
class NumInGroup,
class Length >
434 return Entry(entry_, size_, version_);
446 return entry_ == other.entry_;
452 return entry_ != other.entry_;
458 return entry_ < other.entry_;
464 return entry_ > other.entry_;
472 entry_ = advanceByBytes(entry_, size_);
482 entry_ = advanceBackByBytes(entry_, size_);
493 return Iterator(advanceByBytes(entry_, distance * size_), size_, version_);
502 return Iterator(advanceBackByBytes(entry_, distance * size_), size_, version_);
523 , blockLength_(blockLength)
528 assert(blockLength > 0);
529 assert(version != 0);
553 return Iterator(
encoded(), blockLength_, version_);
567 assert(index < size_);
570 return Entry(advanceByBytes(encoded_,
static_cast<ptrdiff_t
>(index) * blockLength_), blockLength_, version_);
586 template<
class OtherEntry,
class OtherBlockLength,
class OtherNumInGroup,
class OtherLength >
588 : encoded_(other.encoded_)
589 , blockLength_(other.blockLength_)
591 , version_(other.version_)
596 assert(blockLength_ == other.blockLength_);
597 assert(size_ == other.size_);
600 template <
class OtherEntry,
class OtherBlockLength,
class OtherNumInGroup,
class OtherLength>
603 encoded_ = other.encoded_;
605 blockLength_ = other.blockLength_;
607 assert(blockLength_ == other.blockLength_);
611 assert(size_ == other.size_);
613 version_ = other.version_;
620 template <
class OtherEntry,
class OtherBlockLength,
class OtherNumInGroup,
class OtherLength>
friend class SbeGroupEntries;
623 BlockLength blockLength_;
629template <
class EntryType,
class DimensionType,
class GroupSizeType >
646 typedef SbeGroupEntries <EntryType, typename Dimension::BlockLength, typename Dimension::NumInGroup, GroupSizeType >
Entries;
669 : header_(
static_cast <Dimension*
>(data))
731 assert(index <
size());
743 return Entries (entries_, header_->blockLength(), header_->numInGroup(), version_);
790 Dimension*
const group =
static_cast<Dimension*
>(header_);
791 group->setBlockLength(entrySize);
792 group->setNumInGroup(0);
796 Size allocate(Size entryCount,
const void* messageTail,
const void* blockEnd)
802 Dimension*
const group =
static_cast<Dimension*
>(header_);
804 const EntrySize entrySize = group->blockLength();
806 if ONIXS_ILINK3_UNLIKELY(
807 entrySize < EntryType::blockLength(version_))
809 throwBadBinaryBlock();
812 const Size oldEntryCount = group->numInGroup();
814 if(oldEntryCount == entryCount)
817 const ptrdiff_t memShift =
818 (entryCount - oldEntryCount) *
static_cast<ptrdiff_t
>(entrySize);
820 const void*
const newMessageTail =
821 advanceByBytes(messageTail, memShift);
823 if ONIXS_ILINK3_UNLIKELY(byteDistance(blockEnd, newMessageTail) < 0)
824 throwNotEnoughSpace();
826 const
void* const oldEndOfGroup =
827 advanceByBytes(entries_, static_cast<ptrdiff_t>(entrySize) * oldEntryCount);
829 void* const newEndGroup =
830 advanceByBytes(entries_, static_cast<ptrdiff_t>(entrySize) * entryCount);
835 byteDistance(messageTail, oldEndOfGroup));
837 group->setNumInGroup(entryCount);
839 return oldEntryCount;
844 void setup(Size entryCount, const
void* messageTail, const
void* blockEnd)
850 const Size oldEntryCount = allocate(entryCount, messageTail, blockEnd);
852 for(Size index = oldEntryCount; index < entryCount; ++index)
853 zeroPaddingBytes((*
this)[index].resetVariableFields());
858 void construct(Size entryCount,
const void* messageTail,
const void* blockEnd)
864 const Size oldEntryCount = allocate(entryCount, messageTail, blockEnd);
866 for(Size index = oldEntryCount; index < entryCount; ++index)
867 zeroPaddingBytes((*
this)[index].reset());
871 static void zeroPaddingBytes(Entry& entry)
873 assert(entry.valid());
874 entry.zeroPaddingBytes(EntryType::minimalBlockLength(entry.version()));
886template <
class BinarySize >
906 template<
class BinaryVariableLengthFieldType>
909 return *
static_cast<BinaryVariableLengthFieldType*
>(binary_);
920 assert(headSize <= size_);
931 if ONIXS_ILINK3_UNLIKELY(
empty() || (size_ < BinaryVariableLengthFieldType::Size))
933 throwBadBinaryBlock();
938 if ONIXS_ILINK3_UNLIKELY(headSize > size_)
940 throwBadBinaryBlock();
954template <
class BinarySize>
979 return Group(binary_, size_, version_);
988 const BinarySize headSize =
head<Group>().binarySize();
990 assert(headSize <= size_);
992 return SbeGroupList(advanceByBytes(binary_, headSize), size_ - headSize, version_);
1001 const BinarySize headSize =
head<Group>().binarySize();
1003 assert(headSize <= size_);
1014 const BinarySize headSize = checkHead<Group>();
1016 return SbeGroupList(advanceByBytes(binary_, headSize), size_ - headSize, version_);
1025 const BinarySize headSize = checkHead<Group>();
1031 template<
class Group>
1032 BinarySize checkHead()
const
1034 if ONIXS_ILINK3_UNLIKELY(size_ < Group::Dimension::Size)
1036 throwBadBinaryBlock();
1039 const Group group = head<Group>();
1041 const BinarySize headSize = group.binarySize();
1043 if ONIXS_ILINK3_UNLIKELY(headSize > size_)
1045 throwBadBinaryBlock();
1050 const BinarySize entrySize = group.entrySize();
1051 const BinarySize expectedEntrySize = Group::Entry::minimalBlockLength(version_);
1053 if ONIXS_ILINK3_UNLIKELY(entrySize < expectedEntrySize)
1055 throwBadBinaryBlock();
1068template<
typename Traits>
1071 if ONIXS_ILINK3_UNLIKELY(version < Traits::MinimalVersion)
1073 throwBadMessageVersion(version, Traits::MinimalVersion);
1078template<
typename Traits>
1083 if ONIXS_ILINK3_UNLIKELY(version < since)
1085 throwBadMessageVersion(version, since);
1090template<
typename Traits>
1093 if ONIXS_ILINK3_UNLIKELY(
id != Traits::Id)
1095 throwBadSchemaId(Traits::Id,
id);
1100template<
typename Traits>
1194 return header_->templateId();
1202 return header_->version();
1210 return header_->schemaId();
1234 return advanceByBytes(header_, size_);
1242 return advanceByBytes(header_, size_);
1264 return header_->blockLength();
1307 return GroupList(list, listSize, header_->version());
1320 return GroupList(
const_cast<void*
>(list), listSize, header_->version());
1324 template<
typename Group>
1328 assert(group.valid());
1329 group.init(entrySize);
1333 template<
typename Group>
1335 void setupGroup(Group& group,
typename Group::Size entryCount,
const void* messageTail)
1337 assert(messageTail);
1338 assert(group.valid());
1339 group.setup(entryCount, messageTail,
blockEnd());
1343 template<
typename Group>
1345 void constructGroup(Group& group,
typename Group::Size entryCount,
const void* messageTail)
1347 assert(messageTail);
1348 assert(group.valid());
1349 group.construct(entryCount, messageTail,
blockEnd());
1355 assert(oldMessageTail);
1357 const ptrdiff_t lengthChange =
static_cast<ptrdiff_t
>(value.length() - data.
length());
1359 const void*
const newMessageTail = advanceByBytes(oldMessageTail, lengthChange);
1361 if ONIXS_ILINK3_UNLIKELY(byteDistance(
blockEnd(), newMessageTail) < 0)
1362 throwNotEnoughSpace();
1364 const void*
const oldEndOfData = advanceByBytes(data.
varData().data(), data.
varData().size());
1366 void*
const newEndOfData = toOpaquePtr(advanceByBytes(&data, value.length() +
DATA::Size));
1368 std::memmove(newEndOfData, oldEndOfData, byteDistance(oldMessageTail, oldEndOfData));
1412 header_->setTemplateId(value);
1414 header_->setSchemaId(
id);
1424 const ptrdiff_t distance = byteDistance(tail,
binary());
1426 assert(distance > 0);
1428 assert(distance <= (std::numeric_limits<MessageSize>::max)());
1432 assert(size <= size_);
1438 template<
class Callable,
class Owner>
1445 template<
class Callable,
class Owner>
1448 if ONIXS_ILINK3_UNLIKELY(since >
version())
1449 throwDisallowedField();
1455 template<
class Callable,
class Owner>
1458 ONIXS_ILINK3_CHECK_NOTHROW(callable(owner));
1459 return callable(owner).varData();
1463 template<
class Callable,
class Owner>
1466 if ONIXS_ILINK3_UNLIKELY(since >
version())
1473 template<
class Callable,
class Owner>
1476 ONIXS_ILINK3_CHECK_NOTHROW(callable(owner));
1477 callable(owner).length(0);
1481 template<
class Group,
class Callable,
class Owner>
1484 const typename Group::EntrySize entrySize = Group::Entry::blockLength(
version());
1486 Group grp = callable(owner);
1492 template<
class Callable,
class Owner>
1495 if ONIXS_ILINK3_UNLIKELY(since >
version())
1502 template<
class Group,
class Callable,
class Owner>
1505 if ONIXS_ILINK3_UNLIKELY(since >
version())
1512 template<
class Group,
class Callable,
class Owner>
1515 ONIXS_ILINK3_CHECK_NOTHROW(callable(owner));
1516 return callable(owner);
1520 template<
class Group,
class Callable,
class Owner>
1523 if ONIXS_ILINK3_UNLIKELY(since >
version())
1530 template<
class Group,
class Callable,
class Owner>
1533 if ONIXS_ILINK3_UNLIKELY(since >
version())
1540 template<
class Group,
class Callable,
class Owner>
1543 Group group = callable(owner);
1551 template<
class Group,
class Callable,
class Owner>
1554 if ONIXS_ILINK3_UNLIKELY(since >
version())
1561 template<
class Group,
class Callable,
class Owner>
1562 Group
setupGroup(Callable callable,
typename Group::Size length, Owner& owner)
1564 Group group = callable(owner);
#define ONIXS_ILINK3_MESSAGING_NAMESPACE_END
#define ONIXS_ILINK3_LTWT_CLASS
#define ONIXS_ILINK3_MESSAGING_NAMESPACE_BEGIN
#define ONIXS_ILINK3_LTWT_EXPORTED
#define ONIXS_ILINK3_HOTPATH
#define ONIXS_ILINK3_NODISCARD
#define ONIXS_ILINK3_NULLPTR
#define ONIXS_ILINK3_CONSTEXPR
#define ONIXS_ILINK3_UNUSED
#define ONIXS_ILINK3_DEFAULT
#define ONIXS_ILINK3_NOTHROW
bool decimal(Value &value, BlockLength offset, NullValue null) const noexcept
bool fixedStr(StrRef &value, BlockLength offset) const noexcept
Provides access to an optional string field value.
Value ordinary(BlockLength offset) const noexcept
bool fixedStr(StrRef &value, BlockLength offset, SchemaVersion since) const noexcept
Provides access to an optional string field value.
bool ordinary(Value &value, BlockLength offset, NullValue null) const noexcept
Provides access to an optional field value.
bool decimal(Value &value, BlockLength offset, NullValue null, SchemaVersion since) const noexcept
Value decimal(BlockLength offset) const noexcept
Enumeration::Enum enumeration(BlockLength offset) const noexcept
bool enumeration(typename Enumeration::Enum &value, BlockLength offset, NullValue null) const noexcept
Provides access to an optional field value.
BinaryBlock()=default
Initializes a blank instance.
bool ordinary(Value &value, BlockLength offset, NullValue null, SchemaVersion since) const noexcept
Provides access to an optional field value.
StrRef fixedStr(BlockLength offset) const noexcept
Provides access to a string field value.
bool enumeration(typename Enumeration::Enum &value, BlockLength offset, NullValue null, SchemaVersion since) const noexcept
Provides access to an optional field value.
NumInGroup numInGroup() const noexcept
BlockLength blockLength() const noexcept
SbeFields()=default
Initializes a blank instance.
Container & container() noexcept
void zeroPaddingBytes(BlockLength offset) noexcept
If specified, the extra space is padded at the end of each entry and should be set to zeroes by encod...
void setFixedStr(BlockLength offset, StrRef value) noexcept
Sets the field value.
void setOrdinary(BlockLength offset, FieldValue value, SchemaVersion since)
Sets the field value.
void setEnumeration(BlockLength offset, typename Enumeration::Enum value, SchemaVersion since)
Sets the field value.
void setEnumeration(BlockLength offset, typename Enumeration::Enum value) noexcept
Sets the field value.
void setOrdinary(BlockLength offset, FieldValue value) noexcept
Sets the field value.
void setFixedStr(BlockLength offset, StrRef value, SchemaVersion since)
Sets the field value.
An iterator over SBE-encoded group entries.
Iterator(void *entry, Size size, SchemaVersion version) noexcept
Initializes the instance to the given repeating group.
std::random_access_iterator_tag iterator_category
Iterator() noexcept
Initializes the instance that refers to nothing.
bool valid() const noexcept
ptrdiff_t difference_type
SbeGroupEntries() noexcept
Initializes a blank instance referencing to nothing.
bool empty() const noexcept
SbeGroupEntries(void *encoded, BlockLength blockLength, Size groupSize, SchemaVersion version) noexcept
Initializes the instance referencing to data.
EntryType Entry
The type of the repeating group entry.
Iterator end() const
Returns the iterator pointing to the entry behind the end of the group.
Size size() const noexcept
EncodedLength encodedLength() const noexcept
SbeGroupEntries(const SbeGroupEntries< OtherEntry, OtherBlockLength, OtherNumInGroup, OtherLength > &other) noexcept
Copy constructor.
bool valid() const noexcept
friend class SbeGroupEntries
Length EncodedLength
The length of the binary data occupied by the group entries.
NumInGroup Size
Number of entries in the collection.
void * encoded() const noexcept
SbeGroupEntry()
Initializes a blank instance.
const void * block() const noexcept
SbeGroupEntry(void *encoded, BlockLength size, SchemaVersion version)
Initializes the instance from the memory block of the encoded message.
SchemaVersion version() const noexcept
bool valid() const noexcept
const void * encoded() const noexcept
BlockLength blockLength() const noexcept
void * encoded() noexcept
GroupSize::BlockLength BlockLength
SbeVariableLengthFieldList< BinarySize > checkVariableLengthFields() const
Checks the variable length fields list consistency.
bool empty() const noexcept
SbeGroupList tail() const noexcept
SbeGroupList checkTail() const
Checks the list consistency.
Group head() const noexcept
SbeVariableLengthFieldList< BinarySize > variableLengthFields() const noexcept
SbeGroupList(void *binary, BinarySize size, SchemaVersion version) noexcept
Initializes the list over the memory block.
const void * tail() const noexcept
SbeGroup() noexcept
Initializes a blank instance referencing to nothing.
EntrySize entrySize() const noexcept
BinarySize binarySize() const noexcept
bool empty() const noexcept
GroupSize::BlockLength EntrySize
SbeGroup(void *data, BinarySize size, SchemaVersion version) noexcept
Initializes an instance referencing to a valid group of a given message.
Entries::Iterator Iterator
Entries entries() const noexcept
void * binary() const noexcept
Size size() const noexcept
Iterator end() const noexcept
bool valid() const noexcept
const void * encoded() const noexcept
SbeGroupEntries< QuoteEntry, typename Dimension::BlockLength, typename Dimension::NumInGroup, MessageSize > Entries
Iterator begin() const noexcept
void clear() noexcept
Blank the instance.
const void * binary() const noexcept
MessageTemplateId templateId() const noexcept
SchemaId schemaId() const noexcept
Group setupGroup(Callable callable, typename Group::Size length, SchemaVersion since, Owner &owner)
Setups the repeating group with the given number of entries.
const void * blockEnd() noexcept
GroupList groups() const noexcept
Group setupGroup(Callable callable, typename Group::Size length, Owner &owner)
Setups the repeating group with the given number of entries.
StrRef getVariableLengthField(Callable callable, SchemaVersion since, Owner &owner) const noexcept
const void * blockEnd() const noexcept
void setVariableLengthField(Callable callable, StrRef value, SchemaVersion since, Owner &owner)
Sets the value of the variable length field.
SbeMessage(void *data, MessageSize size)
Initializes the instance over the given memory block.
SbeVariableLengthFieldList< MessageSize > VariableLengthFieldList
Binary group list instantiation.
GroupList groups() noexcept
SbeMessage & version(SchemaVersion version) noexcept
Sets the SBE Schema version.
Group getGroup(Callable callable, Owner &owner) const noexcept
Group getGroup(Callable callable, SchemaVersion since, Owner &owner) const noexcept
MessageSize EncodedLength
Length of the message binary data.
const void * block() const noexcept
SbeMessage(void *data, MessageSize size, NoCheck) noexcept
Initializes the instance over the given memory block.
void initGroup(Group &group, typename Group::EntrySize entrySize) noexcept
Resets the group to the initial state.
void setupGroup(Group &group, typename Group::Size entryCount, const void *messageTail)
Initializes the group header.
VariableLengthFieldList variableLengthFields() const noexcept
SchemaVersion version() const noexcept
SbeGroupList< MessageSize > GroupList
Binary group list instantiation.
SbeMessage(void *data, MessageSize size, SchemaVersion version)
Initializes the instance over the given memory block.
MessageSize bufferSize() const noexcept
bool valid() const noexcept
static constexpr MessageSize getMaxMessageSize() noexcept
Maximal message size.
Group constructGroup(Callable callable, typename Group::Size length, Owner &owner)
Creates a repeating group with the given number of entries, sets all optional fields of the group ent...
Group constructGroup(Callable callable, typename Group::Size length, SchemaVersion since, Owner &owner)
Creates a repeating group with the given number of entries, sets all optional fields of the group ent...
void setVariableLengthFieldToNull(Callable callable, SchemaVersion since, Owner &owner) noexcept
Sets the variable length field to null.
BlockLength blockLength() const noexcept
void setVariableLengthFieldToNull(Callable callable, Owner &owner) noexcept
Resets the variable length field.
void resetGroup(Callable callable, SchemaVersion since, Owner &owner)
Resets the repeating group.
SbeMessage() noexcept
Initializes a blank instance.
void setVariableLengthField(Callable callable, StrRef value, Owner &owner)
Sets the value of the variable length field.
void setVarDataField(DATA &data, StrRef value, const void *oldMessageTail)
Sets the variable length field value.
void init(MessageHeader::TemplateId value, MessageHeader::BlockLength minimalBlockLength, MessageHeader::BlockLength blockLength, SchemaId id) noexcept
VariableLengthFieldList variableLengthFields() noexcept
MessageSize BlockLength
Length of the message body representing a block of fixed-length fields.
StrRef getVariableLengthField(Callable callable, const Owner &owner) const noexcept
void resetGroup(Callable callable, Owner &owner) noexcept
Sets the group to the initial state.
MessageSize calculateBinarySize(const void *tail) const noexcept
void constructGroup(Group &group, typename Group::Size entryCount, const void *messageTail)
Initializes the group header, sets all optional fields to null.
Variable-length fields list.
bool empty() const noexcept
SbeVariableLengthFieldList(void *binary, BinarySize size, SchemaVersion version) noexcept
Initializes the list over the given memory block.
SbeVariableLengthFieldList tail() const noexcept
BinaryVariableLengthFieldType & head() const noexcept
SbeVariableLengthFieldList checkTail() const
Checks the variable-length field list consistency.
void checkSchemaId(SchemaId id)
Checks the compatibility with the provided SBE Schema ID.
MessageHeader::Version SchemaVersion
SBE-encoded data version type.
constexpr UInt16 MaxILink3MessageSize
Maximum supported message size.
char Char
Character type alias.
UInt16 MessageSize
Message length type.
std::basic_string_view< Char > StrRef
void checkVersion(SchemaVersion version)
Checks the compatibility with the provided SBE Schema version.
MessageHeader::SchemaId SchemaId
void checkSchema(SchemaId id, SchemaVersion version)
Checks the compatibility with the provided SBE Schema version.
MessageHeader::TemplateId MessageTemplateId
Message type (template) identification.
StrRef varData() const noexcept
Length length() const noexcept