BitTorrent协议规范之Bencode
来源:互联网 发布:新干网络电视台回放 编辑:程序博客网 时间:2024/06/03 20:18
Bencode(发音为 Bee-Encode)是 BitTorrent 用在传输数据结构的编码方式。这种编码方式支持四种数据:
- 字符串 (Byte String)
- 整数 (Int)
- 线性表 (List)
- 字典表 (Dictionary)
Bencode 最常被用在 .torrent 档中,档案里的元数据都是 Bencode 过的字典表。
Bencode其实非常简单,它就是定义了一套用字符串来表示这四种信息的规则。
字符串用最常见的方法,即 字符串长度:字符串数据。但是这个字符串长度是用ASCII编码,而不是把四个字节表示的Int写正在这里,比如 "10:abcdefghij"表示字符串"abcdefghij"。涉及中文时,用UTF-8编码方式。
整数表示方法是,i 整数的ASCII编码 e 。这里用i表示起始标志,用e表示结束标志。可以表示负数,比如 "i-5e"就表示-5。其中“整数的ASCII编码”除了0外,其它的不能以0开始。比如"i07e"就非法,但是"i0e"就是可以的。
表示的整数不要超过32 Bit。
线性表的表示方法是,l (Bencode数据)* e 。值得注意的是,List中每一项是Bencode的数据,所以List是可以嵌套的。比如"l3:abc4:abcdl3:def4:1234ee"表示的是一个List中有"abc","abcd"和List2,List2中有"def","1234"。
字典表的表示方法是,d ((Bencode字符串key)(Bencode数据value))* e 。字典表中每一项的前面的key必须是Bencode字符串,后面的value则可以是Bencode的四种数据中任意一种。比如"d3:abc4:abcd3:defl3:abc:4:abcdee"就表示字典中有两项,第一项key="abc",value="abcd",第二项的key="def",value则是一个List,List中有"abc", "abcd"。
- BitTorrent协议规范之Bencode
- BitTorrent协议规范之torrent文件
- BitTorrent 协议规范
- BitTorrent 协议规范
- BitTorrent 协议规范
- BitTorrent 协议规范
- [转载] BitTorrent协议规范
- [转载] BitTorrent协议规范
- BitTorrent协议规范
- BitTorrent协议规范
- BitTorrent协议规范
- BitTorrent 协议规范
- BitTorrent协议规范之peer与tracker通讯协议
- BitTorrent协议规范(BitTorrent Protocol Specification)之Peer Wire协议(Peer Wire Protocol)-第四部分
- BitTorrent协议规范(BitTorrent Protocol Specification)系列之B编码(Bencoding)-第一部分
- BitTorrent协议规范(BitTorrent Protocol Specification)之Tracker HTTP/HTTPS Protocol-第三部分
- BitTorrent 协议规范1.0版
- BitTorrent 协议规范(翻译)
- ASP.NET 使用ConfigurationManager读写配置文件
- 使用Tripwire保护Linux文件系统
- C语言学习开始了
- BitTorrent协议标准之peer_id
- BitTorrent协议规范之torrent文件
- BitTorrent协议规范之Bencode
- 为什么要使用Asp.net?
- 请问如何消除如下问题
- 使用 Linux on Power 刀片服务器实现复杂的网络
- 从 Java 平台计算 XPath
- IBM Rational AppScan:跨站点脚本攻击深入解析
- 对话 UNIX:简单的按键操作
- 平淡生活:思念是一种病
- 十二生肖属相年份对照表(农历1900--2103)