basilisp.contrib.bencode
- fn (decode data {:as opts :keys [keywordize-keys key-fn]})
Decode the first value in the bencoded
data
bytes according toopts
and return a [decoded* rest*] vector.The decoded* item in the vector is the decoded value of the first item in
data
while rest* is the remaining unencoded values.If
data
cannot be decoded (e.g. is incomplete or an error occurred), it returns a [nildata
] vector.opts
is a map with the following optional supported keys.- keyword
:keywordize-keys
: if the decoded value is a map, keywordize its keys.
- keyword
:key-fn
: a function which will be called for each key-in a map; cannot be specified if
:keywordize-keys
is also specified- keyword
:string-fn
: a function which will be called for each byte string which is not a map key; default is
basilisp.core/identity
- keyword
- fn (decode-all data)
- fn (decode-all data opts)
Decode all values in the bencoded
data
bytes and return them as a [values* incomplete*] vector.The values* item is a collection of the
data
decoded values, while incomplete* is the rest of thedata
bytes that could not be decoded or nil.opts
is a map supporting the same keys asdecode
.
- fn (encode d)
Encode the object
d
into a byte string usingbencode
encoding.encode
supports encoding the following types:bytes
int
str
, which is first decided to UTF-8bytes
keywords and symbols, which are first converted to strings (including namespace, separated by ‘/’) and then converted using the rules for
str
sPython
list
tuple
Basilisp lists and vectors
dict
maps
Mapping type keys must one of: keywords, symbols, or strings.
This function does not support
float
because thebencode
specification does not support non-integer numerics.Set types (including
frozenset
,set
, or Basilisp’s set types) are not supported due to the requirement that lists retain their original element ordering.