Skip to content

Docs: Wire protocol

Jeff Wendling edited this page Apr 29, 2021 · 7 revisions

TODO: Document the binary format used in https://github.com/storj/drpc/tree/main/drpcwire

  • Packet assembly
  • Frame wire format
  • Kind list

Frames

Frames have this layout

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     Header    |   Stream ID   |   Message ID  |     Length    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
|                            Data...                            |
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

where the Header byte has this bit layout

0b00000000
  ^^    ^^
  ||____||_ Done
  |     |__ Kind
  |________ Control

The Stream ID, Message ID and Length fields are variable width encoded integers using the same format as protobuf. See the protobuf documentation for a discussion on how they are encoded.

Kinds

Value Name Meaning
1 Invoke Invoke is used to invoke an RPC. The body is the name of the RPC.
2 Message Message is used to send messages. The body is an encoded message.
3 Error Error is used to inform that an error happened. The body is an error with a code attached.
4 --- ---
5 Close Close is used to inform that the RPC is dead. It has no body.
6 CloseSend CloseSend is used to inform that no more messages will be sent. It has no body.
7 InvokeMetadata Invoke metadata includes metadata about the next Invoke packet with the same stream ID.
Clone this wiki locally