D5133: wireprotov2: add response type that serializes to indefinite length bytestring

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Wed Oct 17 13:17:18 UTC 2018


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This will be needed in a future patch.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D5133

AFFECTED FILES
  mercurial/wireprotoframing.py
  mercurial/wireprototypes.py

CHANGE DETAILS

diff --git a/mercurial/wireprototypes.py b/mercurial/wireprototypes.py
--- a/mercurial/wireprototypes.py
+++ b/mercurial/wireprototypes.py
@@ -389,3 +389,12 @@
     fullhashseed = attr.ib(default=None)
     serverdercerts = attr.ib(default=None)
     servercadercerts = attr.ib(default=None)
+
+ at attr.s
+class indefinitebytestringresponse(object):
+    """Represents an object to be encoded to an indefinite length bytestring.
+
+    Instances are initialized from an iterable of chunks, with each chunk being
+    a bytes instance.
+    """
+    chunks = attr.ib()
diff --git a/mercurial/wireprotoframing.py b/mercurial/wireprotoframing.py
--- a/mercurial/wireprotoframing.py
+++ b/mercurial/wireprotoframing.py
@@ -1146,6 +1146,14 @@
                         for frame in emitter.send(o.data):
                             yield frame
 
+                    elif isinstance(
+                        o, wireprototypes.indefinitebytestringresponse):
+                        for chunk in cborutil.streamencodebytestringfromiter(
+                            o.chunks):
+
+                            for frame in emitter.send(chunk):
+                                yield frame
+
                     # A regular object is CBOR encoded.
                     else:
                         for chunk in cborutil.streamencode(o):



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list