This is an archive of the discontinued Mercurial Phabricator instance.

httppeer: use our CBOR decoder
ClosedPublic

Authored by indygreg on Sep 4 2018, 2:28 PM.

Details

Summary

We just implemented our own CBOR decoder. Let's use it in
httppeer.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

indygreg created this revision.Sep 4 2018, 2:28 PM
pulkit accepted this revision.Sep 5 2018, 7:57 AM
pulkit added a comment.Sep 5 2018, 8:07 AM

Queued the cbor patches. I think following can improve the code more:

  • Having a cborutil.decodeone() function which can make sure we only have one dcoded value and using that fn instead of decodeall()[0]
  • A cborutil.encode() function to use where we don't want to do streamencode() and use that in place of b''.join() pattern
  • Checking for an empty string being passed in cborutil.decodeall()[0] or cborutil.decodeone()

What do you think?

This revision was automatically updated to reflect the committed changes.
In D4465#68517, @pulkit wrote:

Queued the cbor patches. I think following can improve the code more:

  • Having a cborutil.decodeone() function which can make sure we only have one dcoded value and using that fn instead of decodeall()[0]
  • A cborutil.encode() function to use where we don't want to do streamencode() and use that in place of b''.join() pattern
  • Checking for an empty string being passed in cborutil.decodeall()[0] or cborutil.decodeone()

What do you think?

I agree with all these suggestions. I also think we should teach the sansiodecoder to decode at most one item and use that functionality to build cborutil.decodeone().

FWIW one concern with going down that path is buffer over-read: if we're trying to decode a CBOR value from a stream without advancing past the end of the value, that can be difficult to do without feeding in data in small chunks. But it is doable.