1bee(n)                            BitTorrent                            bee(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       bee - BitTorrent Serialization Format Encoder/Decoder
9

SYNOPSIS

11       package require Tcl  8.4
12
13       package require bee  ?0.1?
14
15       ::bee::encodeString string
16
17       ::bee::encodeNumber integer
18
19       ::bee::encodeListArgs value...
20
21       ::bee::encodeList list
22
23       ::bee::encodeDictArgs key value...
24
25       ::bee::encodeDict dict
26
27       ::bee::decode string ?endvar? ?start?
28
29       ::bee::decodeIndices string ?endvar? ?start?
30
31       ::bee::decodeChannel chan -command cmdprefix ?-exact? ?-prefix data?
32
33       cmdprefix eof token
34
35       cmdprefix error token message
36
37       cmdprefix value token value
38
39       ::bee::decodeCancel token
40
41       ::bee::decodePush token string
42
43______________________________________________________________________________
44

DESCRIPTION

46       The bee package provides de- and encoder commands for data in bencoding
47       (speak 'bee'), the serialization format for data and messages  used  by
48       the BitTorrent protocol.
49

PUBLIC API

51   ENCODER
52       The  package  provides one encoder command for each of the basic forms,
53       and two commands per container, one taking a proper tcl data  structure
54       to  encode  in  the container, the other taking the same information as
55       several arguments.
56
57       ::bee::encodeString string
58              Returns the bee-encoding of the string.
59
60       ::bee::encodeNumber integer
61              Returns the bee-encoding of the integer number.
62
63       ::bee::encodeListArgs value...
64              Takes zero or more bee-encoded values and returns the bee-encod‐
65              ing of their list.
66
67       ::bee::encodeList list
68              Takes  a list of bee-encoded values and returns the bee-encoding
69              of the list.
70
71       ::bee::encodeDictArgs key value...
72              Takes zero or more pairs of keys and values and returns the bee-
73              encoding of the dictionary they form. The values are expected to
74              be already bee-encoded, but the keys must not be. Their encoding
75              will be done by the command itself.
76
77       ::bee::encodeDict dict
78              Takes  a  dictionary  list of string keys and bee-encoded values
79              and returns the bee-encoding of the list. Note that the keys  in
80              the  input must not be bee-encoded already. This will be done by
81              the command itself.
82
83   DECODER
84       The package provides two main decoder  commands,  one  for  decoding  a
85       string expected to contain a complete data structure, the other for the
86       incremental decoding of bee-values arriving on a  channel.  The  latter
87       command  is  asynchronous  and provides the completed decoded values to
88       the user through a command callback.
89
90       ::bee::decode string ?endvar? ?start?
91              Takes the bee-encoding in the string  and  returns  one  decoded
92              value.  In the case of this being a container all contained val‐
93              ues are decoded recursively as well and the result is a properly
94              nested tcl list and/or dictionary.
95
96              If  the optional endvar is set then it is the name of a variable
97              to store the index of the  first  character  after  the  decoded
98              value into. In other words, if the string contains