-
Notifications
You must be signed in to change notification settings - Fork 8
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
Decode dynamic structures in a sensible manner #17
Comments
That's a good idea. Inheritance vs composition: I have only one suggestion - inheritance allows to differentiate information across only one dimension (e.g. things get complicated if we'd like to throw ErrorX and ErrorY, which both occur in different hierarchies stemming from ProphyError. Then we'd need to do a diamond-like inheritance to throw a single error derived from classes from both hierarchies). Using methods or attributes - on the other hand - allows to differentiate information in exception across many attributes independently. Since exception of given class should implement all such attributes/methods/properties, it's probably better to subclass ProphyError by a single error class related to whole family of problems, e.g. prophy.DecodeError I'd definitely prefer to shy away from public 3-or-more-word identifiers, since:
I'd propose a
I could trace adding
That can be added, sure, but let's think what we'd like to achieve this way and whether this is the most readable/maintainable way to get there.
Next line is an unconditional return from function, so the meaning is:
I suppose optional argument |
Summing up: we seem to have two separate problems discussed in this issue:
Which of these problems would you like to solve in related PR - and how? |
Background
I'm often struggling with decoding structures that consist of dynamic arrays. I'm unable to carve the exact payload to provide to the
decode
method because there are no extra markers in the blob I'm working on. When there are some bytes in the payload after decoding, prophy raises enigmaticProphyError
(but it's message is meaningful). I'd like to simplify the logic that a user of the library has to write in such case. For example:Simple error change
We could just subclass the
ProphyError
with something more explicit to use in this particular case. For example:then the user's code could be just:
Potential bug
I think there's a bug related to the behavior I'm observing. To fix it, the library will require slight change in the public interface.
For some reason,
encode
method can receiveterminal
argument but it's unused. On the other hand,decode
lacks such argument but it fills the internal's_decode_impl
terminal
with True all the time. If we could addterminal=True
todecode
, then the user could explicitly state that the structure she is trying to decode is not the final one in the payload and therefore the mentioned error would not be raised at all. The above use case could be compressed to just:Summary
I think that we could implement the new error independently from the second part. As for the interface change, adding
terminal=True
todecode
is just an extension of the interface so it shouldn't be a big problem to introduce it at any time. It turns out that theencode
case is being covered by @kamichal's #16 in the meantime.The text was updated successfully, but these errors were encountered: