FlatBuffers.jl Documentation

Usage

FlatBuffers.jl provides native Julia support for reading and writing binary structures following the google flatbuffer schema (see here for a more in-depth reveiw of the binary format).

The typical language support for flatbuffers involves utilizing the flatc compiler to translate a flatbuffer schema file (.fbs) into a langugage-specific set of types/classes and methods. See here for the official guide on writing schemas.

Currently in Julia, the flatc compiler isn't supported, but FlatBuffers.jl provides a native implementation of reading/writing the binary format directly with native Julia types. What does this mean exactly? Basically you can take a schema like:

namespace example;

table SimpleType {
  x: int = 1;
}

root_type SimpleType;

and do a straightforward Julia translation like:

module Example

using FlatBuffers

type SimpleType
    x::Int32
end

@default SimpleType x=1

end

A couple of things to point out:

So let's see how we can actually use a flatbuffer in Julia:

using FlatBuffers, Example # the schema module we defined above

val = Example.SimpleType(2) # create an instance of our type

flatbuffer = FlatBuffers.build!(val) # start and build a flatbuffer for our SimpleType
val2 = FlatBuffers.read(flatbuffer) # now we can deserialize the value from our flatbuffer, `val2` == `val`

For more involved examples, see the test suite here.

Reference

Documentation is included inline for each type/method, these can be accessed at the REPL by type ?foo where foo is the name of the type or method you'd like more information on.

List of types/methods: