Additional flatc compatibility: bit flags, arrays of scalars in structs, and file identifiers. #366
Open
kraln wants to merge 5 commits into
Open
Additional flatc compatibility: bit flags, arrays of scalars in structs, and file identifiers. #366kraln wants to merge 5 commits into
kraln wants to merge 5 commits into
Conversation
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
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.
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 :-)
file_identifier/root_type: generate aIDENTIFIERassociated constant forthe root table and add a
planus::buffer_has_identifierruntime helperby
Builder::finish(.., Some(id))are byte-compatible with the official implementationAddresses #141 and #55.
[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)
(bit_flags)enums, generated as a dependency-free flags newtypeI 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.