Skip to content

Additional flatc compatibility: bit flags, arrays of scalars in structs, and file identifiers. #366

Open
kraln wants to merge 5 commits into
planus-org:mainfrom
kraln:bit-flags-arrays-and-file-identifier
Open

Additional flatc compatibility: bit flags, arrays of scalars in structs, and file identifiers. #366
kraln wants to merge 5 commits into
planus-org:mainfrom
kraln:bit-flags-arrays-and-file-identifier

Conversation

@kraln

@kraln kraln commented Jun 23, 2026

Copy link
Copy Markdown

Howdy!

I have a system which makes extensive use of flatbuffers as an internal API surface for IPC (over NATS), and many of those services are transitioning to Rust. The official libraries are... not the best developer experience, and there were only a few features the system relies on that planus didn't support.

This MR implements those features (that were missing for my usecase), potentially it'd be useful for everyone else, too :-)

  • Honor file_identifier/root_type: generate a IDENTIFIER associated constant for
    the root table and add a planus::buffer_has_identifier runtime helper
  • Write the file identifier into bytes 4..8 (after the root offset) so buffers produced
    by Builder::finish(.., Some(id)) are byte-compatible with the official implementation

Addresses #141 and #55.

  • Add support for fixed-size arrays of scalars in structs (e.g. [uint8:16])

This was not currently tracked as an issue that I could find, but highlighted in the README.md (which is now updated to remove it, along with the file identifiers/root type)

  • Add support for (bit_flags) enums, generated as a dependency-free flags newtype

I guess this counts as an "exotic" type, which is now supported. The official rust library implements this with a crate dependency, but it seemed like that wouldn't be in-line with planus's goals.

kraln and others added 5 commits June 23, 2026 13:09
Accept the (bit_flags) attribute on enums (unsigned underlying type, member
value = 1 << position) and generate a dependency-free #[repr(transparent)]
newtype with flag constants, bitwise operators and a decomposing Debug. Reads
are infallible, so bit_flags enums flow through codegen like their underlying
integer.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Struct fields may now be fixed-size arrays of scalars (e.g. [uint8:16]),
generated as [T; N] with inline Primitive/WriteAsPrimitive impls so the
elements are written contiguously inside the struct. Non-scalar element types
are rejected with an error.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A schema's file_identifier is attached to its root_type table and exposed as an
IDENTIFIER associated constant, alongside a new planus::buffer_has_identifier
helper. Builder::finish is also fixed to write the identifier into bytes 4..8
after the root offset (the two were previously swapped, on an untested path) so
identifier-bearing buffers match the official implementation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Fixed-size array struct fields are shown as an array whose children are the
individual elements, and bit_flags values are decomposed into their set flags
(e.g. Fault::A | Fault::C) instead of a single-variant lookup.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Update README.md, remove (now incorrect) "we don't support currently" 

- `file_extension`, `file_identifier` and `root_type`
- Fixed-size arrays
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant