Protocol Buffers

此頁面正在建設中。

Protocol Buffers(Protobuf)是 Google 開發的語言中立、平台中立的序列化格式。

概述

  • 比 JSON/XML 更小、更快、更簡單
  • 強型別定義
  • 向後相容性
  • gRPC 的預設序列化格式

基本語法

syntax = "proto3";

message Person {
    string name = 1;
    int32 age = 2;
    repeated string emails = 3;
}

資料類型

Type說明
double, float浮點數
int32, int64整數
bool布林值
string字串
bytes位元組
repeated陣列/列表

Protobuf vs JSON

特性ProtobufJSON
格式二進制文字
大小
速度
可讀性需工具人類可讀
Schema必須可選

相關主題