Relax the enforced correctness rules when decoding?
Hi folks,
I use Bendy in my project for decoding a bencode and it worked very well for me so far. But data on the Internet is not well-formed in all cases. So, I have some problems parsing bencode data which I'm getting from a server because this data is not well-formed (keys are not sorted). I can't tell the server to give me the response I want, because the server doesn't belong to me.
My question: Is there any way to relax the enforced correctness rules to be able to parse the response?
Thanks, Eugene
This is actually a feature that I've wanted to add, and have plans for how to do it. (Essentially, make the state tracker a type parameter of the encoder and decoder, and then define two additional state trackers: one that only enforces nesting, and one that does not enforce anything). I won't have time to work on this until 31 August, though, so if you want to work on it yourself, a good approach would be to organize your work into three pull requests:
- Separate the interface of the state tracker into a trait, and move the methods of the state tracker into an implementation of that trait.
- Parameterize the encoder and decoder with the state tracker object
- Implement a state tracker that doesn't enforce key order
That said, if the keys aren't sorted, then the server simply is not sending valid data, and this should be reported as a bug. Is the server in question public, so that I can gather test data and possibly fix the problem at the source?
Any update on this? I am having the same problem while implementing the bittorent protocol. Most trackers return unsorted keys. This is a huge blocker.
Three years later and this feature still hasn't been implemented. Anyone else looking into fixing this problem? Will try to make work out of it next week.