Add RawValue to save original bencodes bytes without deserializing.#10
Add RawValue to save original bencodes bytes without deserializing.#10canoriz wants to merge 1 commit intobluk:trunkfrom
Conversation
This does occur in a random sampling of "real world" torrent files. Overall, I like having a dedicated Did you try using On the third "advantage", if the If I were to re-implement the raw value functionality (instead of the current |
This works. I never thought of it before implementing the
I put it behind a
I'm not sure what you mean writting a non-serde one. To me, To me, it seems the |
In BitTorrent specification, the
info_hashis calculated from sha1 of bencodedInfostruct. The specification explicitly says: info_hash should be calculated directly from the original bencode, not from the decoded then encoded bencode.For a long time, I calculated
info_hashfrom the decoded then encoded bencode. But recently I encounter a torrent file whoseinfofield has aprivate: 0field, which I don't support now. This resulted to a wronginfo_hash.I understand I can add a
private: Option<u8>field to myInfostruct, and set someserdeattribute likeskip_if_none, this will work perfectly. But I would like to add aRawValuetype, which have some advantages.Advantages
RawValueto calculate correctinfo_hash, no matter what unsupported fields a torrent file has.RawValueout directly, no more encoding fromInfostruct every time. Though it's possible withoutRawValue: we can always keepInfoand bencodedInfoin the same time.Implementation details
I mostly followed the approach of
RawValueinserde_jsonwith some small differences:serde_jsonhas two versions ofRawValue: borrowed and owned, represented by&'a RawValueandBox<RawValue>. I only implemented the owned version, in simpleRawValue, I don't see many use cases of borrowed version ofRawValuein BitTorrent uses.However, we might (I'm not sure by now) have break change if we want to add borrowed version of
RawValuein the future, if we use this only one owned version now.