Bencoded strings are encoded as follows:
<string length encoded in base ten ASCII>:<string data>
, orkey:value
Note that there is no constant beginning delimiter, and no ending delimiter.Example: 4:spam represents the string "spam"
Example: 0: represents the empty string ""Integers are encoded as follows: i
<integer encoded in base ten ASCII>
e The initial i and trailing e are beginning and ending delimiters. You can have negative numbers such as i-3e. Only the significant digits should be used, one cannot pad the Integer with zeroes. such as i04e. However, i0e is valid.Example: i3e represents the integer "3"
我的问题:
问题 1:我应该如何对包含非 ascii 字符的字符串进行 bencode?例如:mûrier
或die höhe Zeit
我应该使用 UTF-8
将这样的字符串转换为字节序列吗?编码,还是另一种?它如何应用于规范?
问题2:如何对非整数进行Bencode,例如1.0002910
或-0.0049172
?
最佳答案
- 根据规范,“所有字符串值均采用 UTF-8 编码。”
- 不属于规范范围;显然不需要。
关于encoding - 如何对非 ASCII 字符串和非整数进行 Bencode?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30243023/