Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax the enforced correctness rules when decoding? #44

Open
eugenesimakin opened this issue Aug 23, 2020 · 3 comments
Open

Relax the enforced correctness rules when decoding? #44

eugenesimakin opened this issue Aug 23, 2020 · 3 comments

Comments

@eugenesimakin
Copy link

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

@eugenesimakin eugenesimakin changed the title Relaxing decoding? Relaxe decoding? Aug 23, 2020
@eugenesimakin eugenesimakin changed the title Relaxe decoding? Relax decoding? Aug 23, 2020
@eugenesimakin eugenesimakin changed the title Relax decoding? Relax the enforced correctness rules when decoding? Aug 23, 2020
@thequux
Copy link
Contributor

thequux commented Aug 23, 2020

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:

  1. Separate the interface of the state tracker into a trait, and move the methods of the state tracker into an implementation of that trait.
  2. Parameterize the encoder and decoder with the state tracker object
  3. 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?

@morr0ne
Copy link

morr0ne commented Jul 2, 2021

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.

@avdb13
Copy link

avdb13 commented Mar 6, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants