bencode: support decoding byte-arrays.
parent
1adabc3168
commit
f3dc124db2
|
@ -7,6 +7,7 @@ USING: bencode linked-assocs tools.test ;
|
|||
{ "4:spam" } [ "spam" >bencode ] unit-test
|
||||
|
||||
{ "3:\x01\x02\x03" } [ B{ 1 2 3 } >bencode ] unit-test
|
||||
{ "\x01\x02\x03" } [ B{ 51 58 1 2 3 } bencode> ] unit-test
|
||||
|
||||
{ { "spam" 42 } } [ "l4:spami42ee" bencode> ] unit-test
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
USING: arrays assocs byte-arrays combinators io
|
||||
io.streams.string kernel linked-assocs math math.parser
|
||||
sequences strings ;
|
||||
io.encodings.binary io.streams.byte-array io.streams.string
|
||||
kernel linked-assocs math math.parser sequences strings ;
|
||||
IN: bencode
|
||||
|
||||
GENERIC: >bencode ( obj -- bencode )
|
||||
|
@ -50,5 +50,10 @@ PRIVATE>
|
|||
[ read-string ]
|
||||
} case ;
|
||||
|
||||
: bencode> ( bencode -- obj )
|
||||
GENERIC: bencode> ( bencode -- obj )
|
||||
|
||||
M: byte-array bencode>
|
||||
binary [ read-bencode ] with-byte-reader ;
|
||||
|
||||
M: string bencode>
|
||||
[ read-bencode ] with-string-reader ;
|
||||
|
|
Loading…
Reference in New Issue