xref: /aosp_15_r20/external/pigweed/pw_rpc/internal/packet.proto (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1// Copyright 2020 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14syntax = "proto3";
15
16package pw.rpc.internal;
17
18option java_package = "dev.pigweed.pw_rpc.internal";
19
20enum PacketType {
21  // To simplify identifying the origin of a packet, client-to-server packets
22  // use even numbers and server-to-client packets use odd numbers.
23
24  // Client-to-server packets
25
26  // The client invokes an RPC. Always the first packet.
27  REQUEST = 0;
28
29  // A message in a client stream. Always sent after a REQUEST and before a
30  // CLIENT_REQUEST_COMPLETION.
31  CLIENT_STREAM = 2;
32
33  // The client received a packet for an RPC it did not request.
34  CLIENT_ERROR = 4;
35
36  // Client has requested for call completion. In client streaming and
37  // bi-directional streaming RPCs, this also indicates that the client is done
38  // with sending requests.
39  CLIENT_REQUEST_COMPLETION = 8;
40
41  // Server-to-client packets
42
43  // The RPC has finished.
44  RESPONSE = 1;
45
46  // The server was unable to process a request.
47  SERVER_ERROR = 5;
48
49  // A message in a server stream.
50  SERVER_STREAM = 7;
51
52  // Reserve field numbers for deprecated PacketTypes.
53  reserved 3;  // SERVER_STREAM_END (equivalent to RESPONSE now)
54  reserved 6;  // CANCEL (replaced by CLIENT_ERROR with status CANCELLED)
55}
56
57message RpcPacket {
58  // The type of packet. Determines which other fields are used.
59  PacketType type = 1;
60
61  // Channel through which the packet is sent.
62  uint32 channel_id = 2;
63
64  // Hash of the fully-qualified name of the service with which this packet is
65  // associated. For RPC packets, this is the service that processes the packet.
66  fixed32 service_id = 3;
67
68  // Hash of the name of the method which should process this packet.
69  fixed32 method_id = 4;
70
71  // The packet's payload, which is an encoded protobuf.
72  bytes payload = 5;
73
74  // Status code for the RPC response or error.
75  uint32 status = 6;
76
77  // Unique identifier for the call that initiated this RPC. Optionally set by
78  // the client in the initial request and sent in all subsequent client
79  // packets; echoed by the server.
80  uint32 call_id = 7;
81}
82