Mercurial > public > mercurial-scm > hg
comparison mercurial/wireprotoframing.py @ 37725:3ea8323d6f95
wireprotov2: change command response protocol to include a leading map
The error handling mechanism for the new wire protocol isn't very
well-defined. This commit takes us a step in the right direction
by introducing a leading CBOR map for command responses. This map
will contain an overall result of the command.
Currently, the map indicates whether the command was overall
successful or if an error occurred. And if an error occurred, that
error is present in the map.
There is still a dedicated error frame. My intent is to use that
for protocol-level errors and for errors that are encountered after
the initial response frame has been sent. This will be clarified in a
later commit.
Differential Revision: https://phab.mercurial-scm.org/D3385
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 14 Apr 2018 15:19:36 -0700 |
parents | deff7cf7eefd |
children | 0c184ca594bb |
comparison
equal
deleted
inserted
replaced
37724:deff7cf7eefd | 37725:3ea8323d6f95 |
---|---|
352 maxframesize=DEFAULT_MAX_FRAME_SIZE): | 352 maxframesize=DEFAULT_MAX_FRAME_SIZE): |
353 """Create a raw frame to send a bytes response from static bytes input. | 353 """Create a raw frame to send a bytes response from static bytes input. |
354 | 354 |
355 Returns a generator of bytearrays. | 355 Returns a generator of bytearrays. |
356 """ | 356 """ |
357 | 357 # Automatically send the overall CBOR response map. |
358 # Simple case of a single frame. | 358 overall = cbor.dumps({b'status': b'ok'}, canonical=True) |
359 if len(data) <= maxframesize: | 359 if len(overall) > maxframesize: |
360 raise error.ProgrammingError('not yet implemented') | |
361 | |
362 # Simple case where we can fit the full response in a single frame. | |
363 if len(overall) + len(data) <= maxframesize: | |
360 flags = FLAG_COMMAND_RESPONSE_EOS | 364 flags = FLAG_COMMAND_RESPONSE_EOS |
361 yield stream.makeframe(requestid=requestid, | 365 yield stream.makeframe(requestid=requestid, |
362 typeid=FRAME_TYPE_COMMAND_RESPONSE, | 366 typeid=FRAME_TYPE_COMMAND_RESPONSE, |
363 flags=flags, | 367 flags=flags, |
364 payload=data) | 368 payload=overall + data) |
365 return | 369 return |
370 | |
371 # It's easier to send the overall CBOR map in its own frame than to track | |
372 # offsets. | |
373 yield stream.makeframe(requestid=requestid, | |
374 typeid=FRAME_TYPE_COMMAND_RESPONSE, | |
375 flags=FLAG_COMMAND_RESPONSE_CONTINUATION, | |
376 payload=overall) | |
366 | 377 |
367 offset = 0 | 378 offset = 0 |
368 while True: | 379 while True: |
369 chunk = data[offset:offset + maxframesize] | 380 chunk = data[offset:offset + maxframesize] |
370 offset += len(chunk) | 381 offset += len(chunk) |