Mercurial > hg
diff mercurial/wireprotoframing.py @ 40020:ed919b90acda
wireprotov2: define type to represent pre-encoded object
An upcoming commit will introduce a caching layer to command
serving. This will require the ability to cache pre-encoded data.
This commit introduces a type to represent pre-encoded data and
teaches the output layer to not CBOR encode an instance of that
type.
Differential Revision: https://phab.mercurial-scm.org/D4772
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 26 Sep 2018 17:16:27 -0700 |
parents | bce1c1af7518 |
children | 86b22a4cfab1 |
line wrap: on
line diff
--- a/mercurial/wireprotoframing.py Wed Sep 26 15:53:49 2018 -0700 +++ b/mercurial/wireprotoframing.py Wed Sep 26 17:16:27 2018 -0700 @@ -22,6 +22,7 @@ encoding, error, util, + wireprototypes, ) from .utils import ( cborutil, @@ -840,10 +841,22 @@ yield createcommandresponseokframe(stream, requestid) emitted = True - for chunk in cborutil.streamencode(o): - for frame in emitter.send(chunk): + # Objects emitted by command functions can be serializable + # data structures or special types. + # TODO consider extracting the content normalization to a + # standalone function, as it may be useful for e.g. cachers. + + # A pre-encoded object is sent directly to the emitter. + if isinstance(o, wireprototypes.encodedresponse): + for frame in emitter.send(o.data): yield frame + # A regular object is CBOR encoded. + else: + for chunk in cborutil.streamencode(o): + for frame in emitter.send(chunk): + yield frame + except Exception as e: for frame in createerrorframe(stream, requestid, '%s' % e,