Coder Social home page Coder Social logo

flatbufferz's Introduction

⚠️ This project is in its early early stages. expect bugs and missing features. ⚠️

About

Generate zig code from flatbuffer schema files which can de/serialize flatbuffer messages. Depends on packaged flatc to parse .fbs files.

Developed against zig version 0.11.0-dev.2213+515e1c93e

This project depends on packaged flatc compiler @v23.3.3, built with zig using a fork of google/flatbuffers.

Usage

zig build

Run packaged flatc

zig build flatc -- <flatc args>

compile from .fbs files

Use flatc-zig to generate zig files from schema (.fbs) files:

zig-out/bin/flatc-zig -o gen -I examples/includes examples/test.fbs

compile from .bfbs files

Optionally use packaged flatc to generate a binary schema (.bfbs) from a schema (.fbs) files:

zig build flatc -- -b --schema --bfbs-comments --bfbs-builtins --bfbs-gen-embed -I examples/includes -o gen/examples examples/test.fbs

Use flatc-zig to generate zig files from binary schema (.bfbs) files:

zig-out/bin/flatc-zig -o gen gen/examples/test.bfbs

use compiled zig files

Either of these create the following in gen/

$ find gen/ -name "*.fb.zig"
gen/Race.fb.zig
gen/People/X.fb.zig
gen/People/Foo.fb.zig
gen/People/Person.fb.zig

You can now import these files into your zig application. The compiled .fb.zig files depend on a "flatbufferz" module which can be provided by:

// build.zig.zon
.{
    .name = "my-app",
    .version = "0.0.1",

    .dependencies = .{
        .flatbufferz = .{
            // note: you may need to change this url commit hash
            .url = "https://github.com/travisstaloch/flatbufferz/archive/f8c035f29893a2b30902ed61b0d8702e8f52f435.tar.gz",
        },
    }
}
// build.zig
const flatbufferz_dep = b.dependency("flatbufferz", .{
    .target = target,
    .optimize = optimize,
});
const flatbufferz_mod = flatbufferz_dep.module("flatbufferz");
my_exe.addModule("flatbufferz", flatbufferz_mod);

Tools

Convert .bfbs to .fbs.

zig-out/bin/flatc-zig gen/test.bfbs --bfbs-to-fbs

⚠️ warning: --bfbs-to-fbs doesn't produce valid .fbs files. In its current state, it is more of a binary schema debugging tool.

flatbufferz's People

Contributors

travisstaloch avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.