Skip to content

Latest commit

 

History

History
147 lines (125 loc) · 3.51 KB

comparison.md

File metadata and controls

147 lines (125 loc) · 3.51 KB

🏓 Comparison Table

Tip

Looking for Types?

Here are some use cases stacked up.

tinybuf FlatBuffers Protocol Buffers Raw JSON
Serialization format Uint8Array Uint8Array Uint8Array | JSON JSON
Schema definition inline .fbs .proto manual
External compiler deps none cmake and flatc none* none
TypeScript types automatic generated generated manual
Reference data size 34 bytes 68 bytes 72 bytes 175 bytes
Ease-of-use 🟢 🔴 🟢 🟢
Serialization speed 🟢 🟢 🟡 🔴
Memory use 🟢# 🟢 🔴 🔴
Property mangling support 🟢 🟡 🔴 🔴
Suitability for web APIs 🔴 🔴 🟢 🟢
Suitability for games
/ real-time applications
🟢 🟢 🟡 🔴
Supports HTML5 / Node.js 🟢 🟢 🟢 🟢
Supports other languages
(e.g. C, C++, Java, Python)
🔴 🟢 🟢 🟢
float16 / bfloat16 encoding 🟢 🔴 🔴 🔴
scalar encoding 🟢 🔴 🔴 🔴
boolarray encoding 🟢 🔴 🔴 🔴
Arbitrary JSON 🟢 🔴 🔴 🟢
Arbitrary buffer-like data 🟢 🔴 🔴 🟢

Based on the Reference data formats and schemas

*When using protobufjs

#When decoding in-place, and encoding with shared buffer.

See Reference data

Sample data (Minified JSON):

{
  "players": [
    {
      "id": 123,
      "position": {
        "x": 1.0,
        "y": 2.0,
        "z": 3.0
      },
      "velocity": {
        "x": 1.0,
        "y": 2.0,
        "z": 3.0
      },
      "health": 1.00
    },
    {
      "id": 456,
      "position": {
        "x": 1.0,
        "y": 2.0,
        "z": 3.0
      },
      "velocity": {
        "x": 1.0,
        "y": 2.0,
        "y": 3.0
      },
      "health": 0.50
    }
  ]
}

tinybuf

const ExampleMessage = defineFormat({
  players: [
    {
      id: Type.UInt,
      position: {
        x: Type.Float16,
        y: Type.Float16,
        z: Type.Float16
      },
      velocity: {
        x: Type.Float16,
        y: Type.Float16,
        y: Type.Float16
      },
      health: Type.UScalar
    },
  ],
})

FlatBuffers

// ExampleMessage.fbs

namespace ExampleNamespace

table Vec3 {
  x: float
  y: float
  z: float
}

table Player {
  id: uint
  position: Vec3
  velocity: Vec3
  health: float
}

table ExampleMessage {
  players: [Player]
}

root_type ExampleMessage

Protocol Buffers (Proto3)

syntax = "proto3"

package example

message Vec3 {
  float x = 1
  float y = 2
  float z = 3
}

message Player {
  uint32 id = 1
  Vec3 position = 2
  Vec3 velocity = 3
  float health = 4
}

message ExampleMessage {
  repeated Player players = 1
}