0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Protocol BuffersのBase128Varintsについて

Posted at

初めに

https://protobuf.dev/programming-guides/encoding/

上記、ドキュメントに記載されている、Base 128 Varintsについてわからないため、ChatGPTに聞いて理解したのでまとめる。

Base 128 Varints の考え方

Protocol Buffersでは、整数値(int32, int64, uint32, bool など)を効率的にバイナリで表現するためにBase128Varintという形式が使わるみたい。
以下は 150(10進数)を Varint 形式でエンコードする例だ。

  1. 2進数に変換
    150(10進数) ➡ 10010110(2進数)

  2. 7bitに分割
    ここでは、上記の2進数を7bitで分割を行います。
    0000001 0010110

  3. 継続ビット(MSB)を付ける
    次のバイトがある場合は1を追加します。なければ0を追加する。
    00000001 10010110

  4. 反転させて16進数にする
    10010110 00000001 ➡ 0x96 0x01

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?