Bencode
Bencode is a data format . It is through the sharing - protocol BitTorrent used to store and exchange data.
The format supports four data types .
- Whole numbers .
- Variable length strings .
- Lists.
- Associative lists .
Bencode is used, among other things, in .torrent
files. The BitTorrent standard specified to the fact that these files in the specification also called MetaInfo files should be bencodete associative lists.
Since it is a relatively simple algorithm, Bencode can be implemented and parsed very easily . It is also immune to some of the problems that binary formats often encounter. For example, the byte order is irrelevant.
Encoding
Bencode uses ASCII letters as separators.
numbers
Numbers are i<zahl>e
coded as. It is <zahl>
the ASCII version number, base 10. Negative numbers are written with a minus symbol. Bencode does not support fixed point or floating point numbers .
number | Bencode |
---|---|
−234 |
i-234e
|
0 |
i0e
|
29410 |
i29410e
|
Strings
Strings are <länge>:<inhalt>
output as. Here is <länge>
the length, base 10, and <inhalt>
the string itself. Empty strings are output with the length zero.
String | Bencode |
---|---|
−234 |
0:
|
Hello World |
10:Hallo Welt
|
Lists
Lists are l<inhalt>e
output as. It is <inhalt>
the lined, bencodeten elements of the list, in the order in which they should appear. A list can contain a mixture of different data types (e.g. a mixture of numbers and strings). An empty list is le
output as (i.e. without content).
content | Bencode |
---|---|
[] |
le
|
[595] |
li595ee
|
[Hello] |
l5:Halloe
|
[-343, Hello, 555, [], [5]] |
li-343e5:Halloi555eleli5eee
|
Dictionaries
Associative lists, also called dictionaries in English (and in the specification) , are displayed in this form, similar to normal lists d<inhalt>e
. The content consists of chained pairs of two elements, a key and a value . The order of the pairs must be in lexocographical order . An empty dictionary is de
output as.
content | Bencode |
---|---|
{} |
de
|
{Name => Thomas, age => 34} |
d4:Name6:Thomas5:Alteri34ee
|
See also
Individual evidence
- ↑ The Bit Torrent Protocol Specification . BitTorrent.org. Retrieved October 8, 2018.
- ↑ The BitTorrent Specification v1.0: Bencoding . Theory.org. Retrieved October 9, 2018.