encoding - 如何对非 ASCII 字符串和非整数进行 Bencode?

标签 encoding bencoding

根据bencoding specification :

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 字符的字符串进行 bencode?例如:mûrierdie höhe Zeit我应该使用 UTF-8 将这样的字符串转换为字节序列吗?编码,还是另一种?它如何应用于规范?

问题2:如何对非整数进行Bencode,例如1.0002910-0.0049172

最佳答案

  1. 根据规范,“所有字符串值均采用 UTF-8 编码。”
  2. 不属于规范范围;显然不需要。

关于encoding - 如何对非 ASCII 字符串和非整数进行 Bencode?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30243023/

相关文章:

c# - 解码 (BEncode) 种子文件

java - 为什么散列信息字典会出错?

java - java中Bencode字符串长度

.net - SQLite中uniqueidentifier中的乱码文本

ruby - 删除 ruby 中奇怪的无效字符

c# - C#中的Base 64编码

java - 如何处理 Mazovia 编码文本

java - 编码 ISO-8859-5 的 jedis 或 redis 问题