Bencode
From Just Solve the File Format Problem
(Difference between revisions)
Dan Tobias (Talk | contribs) (Created page with "{{FormatInfo |formattype=electronic |subcat=Serialization }} '''Bencode''' (pronounced B-Encode, not Ben Code) is a serialization encoding format used in for torrent file...") |
Dan Tobias (Talk | contribs) m |
||
Line 4: | Line 4: | ||
}} | }} | ||
− | '''Bencode''' (pronounced B-Encode, not Ben Code) is a serialization encoding format used in | + | '''Bencode''' (pronounced B-Encode, not Ben Code) is a serialization encoding format used in [[torrent file]]s in the BitTorrent protocol. It consists of a series of strings, integers, lists, and dictionaries; since lists and dictionaries contain multiple elements of the Bencode types, they can be nested hierarchically, encapsulating complex data structures. |
The elements are: | The elements are: |
Revision as of 05:12, 12 December 2012
Bencode (pronounced B-Encode, not Ben Code) is a serialization encoding format used in torrent files in the BitTorrent protocol. It consists of a series of strings, integers, lists, and dictionaries; since lists and dictionaries contain multiple elements of the Bencode types, they can be nested hierarchically, encapsulating complex data structures.
The elements are:
- Strings: coded as a decimal number giving the length of the string, then a colon, then the string itself; e.g., 5:stuff
- Integers: coded as the letter "i", then the integer (as a series of decimal digits), then the letter "e"' e.g., i42e
- Lists: coded as the letter "l", then the list elements (each encoded as one of the Bencode types, which can include other lists), then the letter "e"; e.g., li42e5:stuffi666ee (which contains 42, 'stuff', and 666 as its elements)
- Dictionaries: pairs of keys and values, where the key is a string and the value can be any Bencode type; surrounded by an opening letter 'd' and closing letter 'e'; keys must appear in alphabetic order; e.g., d4:testi42e3:zzz4:junke is a dictionary where key 'test' has value 42 and key 'zzz' has value 'junk'.