我对 LEB128 或 Little Endian Base 128 格式感到困惑。在AOSP
源代码Leb128.java
中,其read函数的返回类型无论有符号还是无符号都是int
。我知道java中int
的大小是4个字节,又名32bits
。但 AOSP 中 LEB128
的最大长度是 5 个字节,即 35 位
。那么其他丢失的3bits
在哪里。
感谢您的回复。
最佳答案
LEB 中的每个字节数据在实际输出中仅占 7 位 - 剩余的位用于指示是否结束。
来自Wikipedia :
To encode an unsigned number using unsigned LEB128 first represent the number in binary. Then zero extend the number up to a multiple of 7 bits (such that the most significant 7 bits are not all 0). Break the number up into groups of 7 bits. Output one encoded byte for each 7 bit group, from least significant to most significant group.
额外的位并不是“丢失”,而是“用于指示是否是数据的结尾”。
您不能指望对任意 32 位值进行编码,并且其中某些占用的字节数少于 4 个字节,而某些占用的字节数却超过 4 个字节。
关于java - Android LEB128 字号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39725046/