gRPC を触りはじめて, Protocol Buffers についての理解がなかったので概要を理解するためのメモ書きです。
Protocol Buffers とは
ドキュメントが整備されていました。
- Overview | Protocol Buffers Documentation
Overview
Protocol Buffers are a language-neutral, platform-neutral extensible mechanism for serializing structured data.
It’s like JSON, except it’s smaller and faster, and it generates native language bindings. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages.
Protocol buffers are a combination of the definition language (created in .proto files), the code that the proto compiler generates to interface with data, language-specific runtime libraries, the serialization format for data that is written to a file (or sent across a network connection), and the serialized data.
そもそもそんなに理解できてませんでしたが、 Protocol Buffers は, データの通信や永続化において, 構造データのシリアライズ(バイト列に変換する)を行うための仕様やライブラリを指すようです。 定義言語 (.proto ファイルで作成), データとのインターフェイス用に proto コンパイラが生成するコード, 言語固有のランタイムライブラリ, ファイルに書き込まれたり、ネットワーク接続を介して送信されるデータのシリアル化形式、およびシリアル化されたデータの組み合わせになるようです。 Protocol Buffer 自体は Google により開発が進められているようです。
RESTでいうJSONの役割に相当するものなイメージですが、JSONとの違いとして, Protocol Buffers は, フォーマットがスキーマに依存するという点があり、これによりスキーマファースト開発を行えるのが gRPC と Protocol Buffers を使う際の良さのひとつで, 最初にスキーマを定義して、サーバーとクライアントの開発を並行して進めることができるのがメリットの一つらしいです。
また、gRPC はデフォルトで Protocol Buffers を使うようになっているようです。
Protocol Buffers のバージョンは v2 と v3 があるようです。違いについてはまだよく分かってません。
- https://protobuf.dev/programming-guides/proto3/#services
The most straightforward RPC system to use with protocol buffers is gRPC: a language- and platform-neutral open source RPC system developed at Google. gRPC works particularly well with protocol buffers and lets you generate the relevant RPC code directly from your .proto files using a special protocol buffer compiler plugin.
If you don’t want to use gRPC, it’s also possible to use protocol buffers with your own RPC implementation. You can find out more about this in the Proto2 Language Guide.
There are also a number of ongoing third-party projects to develop RPC implementations for Protocol Buffers. For a list of links to projects we know about, see the third-party add-ons wiki page.
gRPC では Protocol Buffers v3 を使うのが推奨のようです。
Google により開発されています。