如何对非 ascii 字符串和非整数进行编码?
How to bencode non-ascii strings and non-integer numbers?
Bencoded strings are encoded as follows: <string length encoded in base ten ASCII>:<string data>
, or key: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 字符的字符串进行编码?例如:mûrier
或 die höhe Zeit
我应该使用 UTF-8
编码还是其他编码将这样的字符串转换为字节序列?它如何应用于规范?
问题 2:如何对非整数进行编码,例如 1.0002910
或 -0.0049172
?
- 根据规范,"All character string values are UTF-8 encoded."
- 规范未涵盖;显然不需要。
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 字符的字符串进行编码?例如:mûrier
或 die höhe Zeit
我应该使用 UTF-8
编码还是其他编码将这样的字符串转换为字节序列?它如何应用于规范?
问题 2:如何对非整数进行编码,例如 1.0002910
或 -0.0049172
?
- 根据规范,"All character string values are UTF-8 encoded."
- 规范未涵盖;显然不需要。