This is an archive of the discontinued Mercurial Phabricator instance.

wireproto: syntax for encoding CBOR into frames
ClosedPublic

Authored by indygreg on Mar 26 2018, 2:12 PM.

Details

Summary

We just vendored a library for encoding and decoding the CBOR
data format. While the intent of that vendor was to support state
files, CBOR is really a nice data format. It is extensible and
compact.

I've been feeling dirty inventing my own data formats for
frame payloads. While custom formats can always beat out a generic
format, there is a cost to be paid in terms of implementation,
comprehension, etc. CBOR is compact enough that I'm not too
worried about efficiency loss. I think the benefits of using
a standardized format outweigh rolling our own formats. So
I plan to make heavy use of CBOR in the wire protocol going
forward.

This commit introduces support for encoding CBOR data in frame
payloads to our function to make a frame from a human string.
We do need to employ some low-level Python code in order to
evaluate a string as a Python expression. But other than that,
this should hopefully be pretty straightforward.

Unit tests for this function have been added.

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.Mar 26 2018, 2:12 PM
indygreg updated this revision to Diff 7327.Mar 26 2018, 5:35 PM
indygreg updated this revision to Diff 7352.Mar 28 2018, 6:05 PM
indygreg updated this revision to Diff 7437.Mar 30 2018, 4:32 PM

I have misgivings about this code that serves testing living in core, but I don't see a better solution offhand.

durin42 accepted this revision.Apr 3 2018, 11:35 AM
This revision is now accepted and ready to land.Apr 3 2018, 11:35 AM
This revision was automatically updated to reflect the committed changes.
yuja added a subscriber: yuja.Apr 4 2018, 9:21 AM
yuja added inline comments.
mercurial/utils/stringutil.py
526

Can't we use ast.literal_eval() instead of unsafe eval() ?

https://docs.python.org/2.7/library/ast.html#ast.literal_eval