flatbuffers

google / flatbuffers

FlatBuffers 是内存高效的跨平台序列化库,支持零拷贝直接访问数据,无需解析即可读取字段,适用于性能敏感的通信与存储场景。

C++ 基础设施 开发工具 桌面/移动应用 序列化 零拷贝 跨平台 高性能

为什么值得看

编辑点评

相比 Protocol Buffers,它省去了反序列化过程,访问数据几乎零开销,非常适合游戏、高频 RPC 和嵌入式系统。不过使用前需用 schema 生成代码,上手有一定学习成本,且生态相对小众。若追求极致性能且能接受约束,值得一试。

Star 趋势

近 7 日
  • Star 总数26,473
  • 今日新增+5
  • 7 日增速+400%
  • Fork3,660

同类项目

同场景 · 基础设施 / 开发工具 / 桌面/移动应用

项目文档

来自 GitHub README · master 分支

logo FlatBuffers

BuildKite status Fuzzing Status

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

  • Windows
  • macOS
  • Linux
  • Android
  • And any others with a recent C++ compiler (C++ 11 and newer)

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.

文档抓取自 GitHub 仓库 README,版权归原作者所有;已过滤徽章等噪音并经安全消毒后展示。