You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BEP 9 (the protocol for resolving magnet URIs) defines a data packet that consists of a bencoded dictionary followed by arbitrary data (actually a slice of a torrent's info dict), and I would like to parse such a packet using bendy. The best way I've figured out to do this so far is to create a Decoder, call next_object(), retrieve the DictDecoder, iterate through & massage the dict's fields, call DictDecoder::into_raw() after handling all fields, get the length of the raw dict, and use that length as an offset to slice the original payload. This is rather unwieldy, and I believe this could be simplified by just giving Decoder a remaining(self) -> &'ser [u8] method for retrieving all remaining bytes of the payload after doing next_object() + FromBencode::decode_bencode_object().
The text was updated successfully, but these errors were encountered:
I'm doing a workaround. info_begin is the length of your payload - the length of the metadata. It is still using Bendy, we just split the buffer at the right spot and decode both sides, assuming both of them implements FromBencode.
pubstructInfo{// .....}pubstructMetadata{pubmsg_type:u8,pubpiece:u32,pubtotal_size:u32,}implMetadata{/// Tries to extract Info from the given buffer, which is the payload of the extended metadata "data" message.pubfnextract(mutbuf:Vec<u8>,info_begin:usize) -> Result<(Self,Info), error::Error>{let info_buf:Vec<u8> = buf.drain(info_begin..).collect();let info = Info::from_bencode(&info_buf).unwrap();let metadata = Metadata::from_bencode(&buf).unwrap();Ok((metadata, info))}}
BEP 9 (the protocol for resolving magnet URIs) defines a data packet that consists of a bencoded dictionary followed by arbitrary data (actually a slice of a torrent's info dict), and I would like to parse such a packet using bendy. The best way I've figured out to do this so far is to create a
Decoder
, callnext_object()
, retrieve theDictDecoder
, iterate through & massage the dict's fields, callDictDecoder::into_raw()
after handling all fields, get the length of the raw dict, and use that length as an offset to slice the original payload. This is rather unwieldy, and I believe this could be simplified by just givingDecoder
aremaining(self) -> &'ser [u8]
method for retrieving all remaining bytes of the payload after doingnext_object()
+FromBencode::decode_bencode_object()
.The text was updated successfully, but these errors were encountered: