Feature Request
Add FlatBuffers IDL support to Fory compiler, enabling users to define schemas using FlatBuffers .fbs files and generate serialization code through Fory's compilation pipeline.
Is your feature request related to a problem? Please describe
Currently, Fory compiler only supports its native IDL format. Users who have existing FlatBuffers schemas or prefer FlatBuffers IDL syntax cannot leverage Fory's high-performance serialization without manually converting their schemas. This creates friction for teams migrating from FlatBuffers to Fory or those who want to use FlatBuffers IDL as their schema definition language.
Describe the solution you'd like
Implement FlatBuffers IDL parser and translator in Fory compiler with the following specifications:
1. FlatBuffers IDL Parser
- Parse
.fbs files and translate to Fory IR (Intermediate Representation)
2. Scalar Type Mapping
| FlatBuffers Type |
Fory Type |
byte |
int8 |
ubyte |
uint8 |
short / int16 |
int16 |
ushort / uint16 |
uint16 |
int / int32 |
varint32 |
uint / uint32 |
var_uint32 |
long / int64 |
varint64 |
ulong / uint64 |
var_uint64 |
float / float32 |
float32 |
double / float64 |
float64 |
3. Complex Type Mapping
| FlatBuffers Construct |
Fory Mapping |
struct |
Fory struct with evolving=false |
table |
Fory struct with evolving=true |
enum |
Fory enum |
[T] (array/vector) |
Fory ListType |
| attribute |
Fory option |
field attributes (e.g., deprecated, priority: 1) |
Fory field options |
union |
Fory union |
4. Auto growing field id
When translate flatbuffer table/struct schema to fory, we should allocate an autogrowing field id to each field, since flatbuffer use this order for schema compatibility.
flatbuffer:
table Foo {
x: float;
y: float;
}
fory:
message {
float32 x = 0;
float32 y = 1;
}
5. Implementation Tasks
Describe alternatives you've considered
-
Manual schema conversion: Users could manually convert FlatBuffers schemas to Fory IDL, but this is error-prone and time-consuming for large schemas.
-
External conversion tool: A standalone tool to convert .fbs to .fory files, but this adds extra steps and doesn't integrate well with the compilation pipeline.
-
Protocol Buffers only: Continue supporting only Protobuf IDL, but this limits adoption from the FlatBuffers community.
Additional context
Example FlatBuffers IDL input:
namespace MyGame.Sample;
enum Color : byte { Red = 0, Green, Blue }
struct Vec3 {
x: float;
y: float;
z: float;
}
table Monster {
pos: Vec3;
mana: short = 150;
hp: short = 100;
name: string;
friendly: bool = false (deprecated, priority: 1);
inventory: [ubyte];
color: Color = Blue;
}
root_type Monster;
Expected behavior:
struct Vec3 maps to Fory struct with evolving=false (fixed layout)
table Monster maps to Fory struct with evolving=true (schema evolution supported)
- Field attributes like
deprecated and priority: 1 map to Fory field options
- Default values are preserved in generated code
References:
Feature Request
Add FlatBuffers IDL support to Fory compiler, enabling users to define schemas using FlatBuffers
.fbsfiles and generate serialization code through Fory's compilation pipeline.Is your feature request related to a problem? Please describe
Currently, Fory compiler only supports its native IDL format. Users who have existing FlatBuffers schemas or prefer FlatBuffers IDL syntax cannot leverage Fory's high-performance serialization without manually converting their schemas. This creates friction for teams migrating from FlatBuffers to Fory or those who want to use FlatBuffers IDL as their schema definition language.
Describe the solution you'd like
Implement FlatBuffers IDL parser and translator in Fory compiler with the following specifications:
1. FlatBuffers IDL Parser
.fbsfiles and translate to Fory IR (Intermediate Representation)2. Scalar Type Mapping
byteint8ubyteuint8short/int16int16ushort/uint16uint16int/int32varint32uint/uint32var_uint32long/int64varint64ulong/uint64var_uint64float/float32float32double/float64float643. Complex Type Mapping
structevolving=falsetableevolving=trueenum[T](array/vector)ListTypedeprecated,priority: 1)union4. Auto growing field id
When translate flatbuffer table/struct schema to fory, we should allocate an autogrowing field id to each field, since flatbuffer use this order for schema compatibility.
flatbuffer:
fory:
5. Implementation Tasks
integration_tests/idl_tests/prototointegration_tests/idl_tests/idland fix all tests.fbstest file atintegration_tests/idl_tests/idlcovering all supported FlatBuffers IDL features exceptuniondocs/compiler/flatbuffers-idl.mddetailing:Describe alternatives you've considered
Manual schema conversion: Users could manually convert FlatBuffers schemas to Fory IDL, but this is error-prone and time-consuming for large schemas.
External conversion tool: A standalone tool to convert
.fbsto.foryfiles, but this adds extra steps and doesn't integrate well with the compilation pipeline.Protocol Buffers only: Continue supporting only Protobuf IDL, but this limits adoption from the FlatBuffers community.
Additional context
Example FlatBuffers IDL input:
Expected behavior:
struct Vec3maps to Fory struct withevolving=false(fixed layout)table Monstermaps to Fory struct withevolving=true(schema evolution supported)deprecatedandpriority: 1map to Fory field optionsReferences: