Mercurial > public > mercurial-scm > hg-stable
diff mercurial/wireprotoframing.py @ 37722:89a16704114c
wireprotov2: define response data as CBOR
Previously, response data was defined as a stream of bytes. We had
the option to declare it as CBOR using a frame flag.
We've converged all wire protocol commands exposed on version 2 to
CBOR. I think consistency is important. The overhead to encoding
things with CBOR is minimal. Even a very large bytestring can be
efficiently encoded using an indefinite length bytestring. Now,
there are limitations with consumers not being able to efficiently
stream large CBOR values. But these feel like solvable problems.
This commit removes the "is CBOR" frame flag from command response
frames and defines the frame as always consisting of a stream of
CBOR values.
The framing protocol media type has been bumped to reflect this
BC change.
Differential Revision: https://phab.mercurial-scm.org/D3382
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 14 Apr 2018 12:07:31 -0700 |
parents | e6870bca1f47 |
children | e8fba6d578f0 |
line wrap: on
line diff
--- a/mercurial/wireprotoframing.py Sat Apr 14 11:49:06 2018 -0700 +++ b/mercurial/wireprotoframing.py Sat Apr 14 12:07:31 2018 -0700 @@ -81,12 +81,10 @@ FLAG_BYTES_RESPONSE_CONTINUATION = 0x01 FLAG_BYTES_RESPONSE_EOS = 0x02 -FLAG_BYTES_RESPONSE_CBOR = 0x04 FLAGS_BYTES_RESPONSE = { b'continuation': FLAG_BYTES_RESPONSE_CONTINUATION, b'eos': FLAG_BYTES_RESPONSE_EOS, - b'cbor': FLAG_BYTES_RESPONSE_CBOR, } FLAG_ERROR_RESPONSE_PROTOCOL = 0x01 @@ -350,7 +348,7 @@ if done: break -def createbytesresponseframesfrombytes(stream, requestid, data, iscbor=False, +def createbytesresponseframesfrombytes(stream, requestid, data, maxframesize=DEFAULT_MAX_FRAME_SIZE): """Create a raw frame to send a bytes response from static bytes input. @@ -360,9 +358,6 @@ # Simple case of a single frame. if len(data) <= maxframesize: flags = FLAG_BYTES_RESPONSE_EOS - if iscbor: - flags |= FLAG_BYTES_RESPONSE_CBOR - yield stream.makeframe(requestid=requestid, typeid=FRAME_TYPE_BYTES_RESPONSE, flags=flags, @@ -380,9 +375,6 @@ else: flags = FLAG_BYTES_RESPONSE_CONTINUATION - if iscbor: - flags |= FLAG_BYTES_RESPONSE_CBOR - yield stream.makeframe(requestid=requestid, typeid=FRAME_TYPE_BYTES_RESPONSE, flags=flags, @@ -616,7 +608,7 @@ return meth(frame) - def onbytesresponseready(self, stream, requestid, data, iscbor=False): + def onbytesresponseready(self, stream, requestid, data): """Signal that a bytes response is ready to be sent to the client. The raw bytes response is passed as an argument. @@ -625,8 +617,7 @@ def sendframes(): for frame in createbytesresponseframesfrombytes(stream, requestid, - data, - iscbor=iscbor): + data): yield frame self._activecommands.remove(requestid) @@ -1067,6 +1058,5 @@ 'request': request, 'expectmore': frame.flags & FLAG_BYTES_RESPONSE_CONTINUATION, 'eos': frame.flags & FLAG_BYTES_RESPONSE_EOS, - 'cbor': frame.flags & FLAG_BYTES_RESPONSE_CBOR, 'data': frame.payload, }