gpt4 book ai didi

.net - BinaryWriter.Write() 如何写字符串

转载 作者:行者123 更新时间:2023-12-03 18:18:39 24 4
gpt4 key购买 nike

我使用BinaryWriter.Write()来写字符串,在msdn中,描述如下:

Writes a length-prefixed string to this stream in the current encoding of the BinaryWriter, and advances the current position of the stream in accordance with the encoding used and the specific characters being written to the stream.



我认为长度前缀是固定大小的;但实际上它是可变大小的。
有关此方法如何计算前缀长度的任何详细信息?

最佳答案

前缀使用无符号 LEB128 格式编码:http://en.wikipedia.org/wiki/LEB128

基本上,如果长度为 127 或更小,则写入单个字节。如果大于,则设置高位,然后写入长度的下 7 位。如果仍然没有足够的位(长度为 16k 或更大),则再次设置高位,并写入另外 7 位。

因此,将有尽可能多的字节来存储长度,每个字节将有 7 位长度,高位将告诉是否存在另一个长度字节。

关于.net - BinaryWriter.Write() 如何写字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1482778/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com