flatbuffers README

The project's README from github.com/google/flatbuffers. As one markdown file: README.md.

logo FlatBuffers

Build status BuildKite status Fuzzing Status Discord Chat Twitter Follow Twitter Follow

FlatBuffers is a cross platform serialization library architected for maximum memory efficiency. It allows you to directly access serialized data without parsing/unpacking it first, while still having great forwards/backwards compatibility.

Quick Start

  1. Build the compiler for flatbuffers (flatc)

    Use cmake to create the build files for your platform and then perform the compilation (Linux example).

    cmake -G "Unix Makefiles"
    make -j
    
  2. Define your flatbuffer schema (.fbs)

    Write the schema to define the data you want to serialize. See monster.fbs for an example.

  3. Generate code for your language(s)

    Use the flatc compiler to take your schema and generate language-specific code:

    ./flatc --cpp --rust monster.fbs
    

    Which generates monster_generated.h and monster_generated.rs files.

  4. Serialize data

    Use the generated code, as well as the FlatBufferBuilder to construct your serialized buffer. (C++ example)

  5. Transmit/store/save Buffer

    Use your serialized buffer however you want. Send it to someone, save it for later, etc...

  6. Read the data

    Use the generated accessors to read the data from the serialized buffer.

    It doesn't need to be the same language/schema version, FlatBuffers ensures the data is readable across languages and schema versions. See the Rust example reading the data written by C++.

Documentation

Go to our landing page to browse our documentation.

Supported operating systems

Supported programming languages

Code generation and runtime libraries for many popular languages.

  1. C
  2. C++ - snapcraft.io
  3. C# - nuget.org
  4. Dart - pub.dev
  5. Go - go.dev
  6. Java - Maven
  7. JavaScript - NPM
  8. Kotlin
  9. Lobster
  10. Lua
  11. PHP
  12. Python - PyPI
  13. Rust - crates.io
  14. Swift - swiftpackageindex
  15. TypeScript - NPM
  16. Nim

Versioning

FlatBuffers does not follow traditional SemVer versioning (see rationale) but rather uses a format of the date of the release.

Contribution

To contribute to this project, see CONTRIBUTING.

Community

Security

Please see our Security Policy for reporting vulnerabilities.

Licensing

Flatbuffers is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.


flatbuffers (google/flatbuffers)

Searching Database…

这是什么?FlatBuffers 是一个跨平台序列化库,主打极致的内存效率:你可以直接读取序列化后的数据,不需要解析或解包步骤,同时还保留了向前和向后的兼容性。
它是链接到我代码里的库,还是一个独立的工具?两者都有:一部分是链接到你应用里的运行时库,另一部分是 flatc 编译器——它读取你的 schema,从 .fbs 文件生成针对具体语言的访问器和构建代码。
把我的数据放进 FlatBuffer 的流程是怎样的?先用 cmake 编译 flatc,在一个 .fbs 文件里定义你的 schema,然后运行 flatc 为你的语言生成代码,用 FlatBufferBuilder 进行序列化,最后用生成的访问器把缓冲区读回来。
我可以从哪些语言里使用它?支持 C、C++、C#、Dart、Go、Java、JavaScript、Kotlin、Lobster、Lua、PHP、Python、Rust、Swift、TypeScript 和 Nim 的代码生成和运行时,通过 npm、PyPI、NuGet、Maven、crates.io、pub.dev 等渠道分发。
把它加为依赖时,版本方面有什么坑吗?有——它的发布版本按日期命名,而不是遵循语义化版本(SemVer),所以在包管理器里锁定版本时,别指望看到 1.2.3 这样的版本号。
它在 Windows 和 macOS 上能用吗,还是只支持 Linux?全都支持——Windows、macOS、Linux 和 Android 都是明确支持的,另外任何有较新 C++ 编译器(C++ 11 或更新)的操作系统也可以。
免费吗?商业使用也可以吗?可以,它采用 Apache License 2.0 许可证,这是一个宽松的开源许可证,没有付费版本。
我能读取用其他语言或旧版 schema 写入的缓冲区吗?可以。读取方不需要使用相同的语言或相同的 schema 版本——FlatBuffers 让数据在不同语言和不同 schema 版本之间都能读取;README 里就演示了 Rust 读取 C++ 写入的缓冲区。
相比 JSON 这种需要解析的格式,选它有什么好处?核心卖点在于:你可以直接访问序列化后的数据,不需要先解析或解包,内存效率正是由此而来,而且跨版本兼容也是内置的。
Creator
google
Size
21.7 MB
Stars
26.6K
Age
12y
Commits · 90 Days