-
-
Notifications
You must be signed in to change notification settings - Fork 55
Comparison With Google FlatBuffers
FlatSharp is a completely independent implementation of the FlatBuffer format. This means implementations of:
- FBS Parser
- Code gen
- Runtime
There is good and bad about this.
- Good: FlatSharp is highly optimized for C# and C# scenarios
- Good: FlatSharp can include features that only make sense in C#
- Bad: FlatSharp can sometimes trail the canonical implementation as new features are added.
In terms of FlatBuffer features, there is a ton of overlap between the implementations:
- Tables, Structs, Vectors, Unions, Strings, Scalars, and Enums
- FlatSharp only allows a single type to be present in a union once (ie,
Union<TableA, TableB, TableA>
is unsupported).
- FlatSharp only allows a single type to be present in a union once (ie,
- Default values for scalars, including optional scalars
- Sorted Vectors
- Shared strings
- Vtable deduplication
- Vectors of Unions
- Fixed-Size struct vectors (
struct Foo { Data : [ulong:16]; }
)
- FlexBuffers
-
force_align
attribute - Structs as root objects (only tables can be roots)
- gRPC
- Different deserialization modes. The Google implementation is always
Lazy
by default. When using theobject-api
switch inflatc
, then it is alwaysGreedy
. - An equivalent to the
IIndexedVector
abstraction over sorted vectors
FlatSharp and the main FlatBuffer library differ substantially in how they are implemented:
FlatSharp builds buffers front-to-back, while the Google implementation builds them back-to-front. Interestingly, the leaf nodes of the object graph tend to end up at the end of the buffer in both implementations. However, the serialized bits will not be identical between the two implementations. The FlatBuffer format is flexible enough to allow many different binary representations of the same message.
FlatSharp was built from the ground up to have first-class support for Memory<T>
and Span<T>
. The Google implementation includes some support for Span<T>
, but the main buffer builder still depends on byte arrays.