Support for BEVE aligned typed arrays#2400
Merged
stephenberry merged 6 commits intomainfrom Mar 27, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Aligned Typed Arrays for BEVE
Adds aligned typed arrays to BEVE, enabling zero-copy access to numeric array data via
std::span<const T>pointing directly into the message buffer.Wire format
A new typed array sub-type (category 3, sub-type 2, tag
0x5C):The
PADDING_LENGTHbyte stores the number of padding bytes so decoders can skip them without tracking absolute byte offsets. The padding aligns DATA to the element type's natural alignment.Writing
Enable with the
aligned_arraysoption:Single-byte types (
uint8_t,int8_t) use standard typed arrays since alignment provides no benefit.Zero-copy reading
Read into
std::span<const T>to get a pointer directly into the buffer — no copies:Works as struct members too — write with
std::vector, read back withstd::span<const T>:The span specialization rejects non-aligned typed arrays with a syntax error (alignment can't be guaranteed). On big-endian systems, reading into
std::span<const T>returnsfeature_not_supportedsince BEVE is little-endian.Changes
header.hpp—tag::aligned_typed_arrayconstant (0x5C)opts.hpp—aligned_arraysoption withcheck_aligned_arrays()write.hpp— Writes aligned header, numeric header, size, padding length byte, padding, then dataread.hpp— Decodes aligned typed arrays;from<BEVE, std::span<const T>>specialization for zero-copyskip.hpp— Skips aligned typed arrays using the stored padding lengthbeve_to_json.hpp— Converts aligned typed arrays to JSONpeek_header.hpp— Peeks at aligned typed array headerssize.hpp— Exact size calculation with offset threading for alignment paddingdocs/binary.md— Documentation for aligned arrays and zero-copy spansValidation
All decode paths validate
padding_length < alignment, rejecting values that violate the spec.Tests
27 new tests covering roundtrips (float32/64, int16/32, uint64), alignment verification, empty arrays,
std::array, nested in objects, beve-to-json conversion, skip paths, peek header, zero-copy spans (double/float/int32/uint64), struct members with spans, rejection of non-aligned buffers and type mismatches, large arrays crossing compressed int boundaries,allow_conversions, variants containing aligned arrays, and map values.