Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 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. |
| 14 | syntax = "proto3"; |
| 15 | |
| 16 | package pw.rpc.internal; |
| 17 | |
Wyatt Hepler | ba43a3c | 2020-08-13 12:45:25 -0700 | [diff] [blame] | 18 | option java_package = "dev.pigweed.pw.rpc.internal"; |
| 19 | |
Wyatt Hepler | af83568 | 2020-06-17 11:42:53 -0700 | [diff] [blame] | 20 | enum PacketType { |
Wyatt Hepler | 0f26235 | 2020-07-29 09:51:27 -0700 | [diff] [blame] | 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. |
Wyatt Hepler | af83568 | 2020-06-17 11:42:53 -0700 | [diff] [blame] | 23 | |
Wyatt Hepler | 0f26235 | 2020-07-29 09:51:27 -0700 | [diff] [blame] | 24 | // Client-to-server packets |
Wyatt Hepler | 712d367 | 2020-07-13 15:52:11 -0700 | [diff] [blame] | 25 | |
Wyatt Hepler | 5ba8064 | 2021-06-18 12:56:17 -0700 | [diff] [blame] | 26 | // The client invokes an RPC. Always the first packet. |
Wyatt Hepler | 0f26235 | 2020-07-29 09:51:27 -0700 | [diff] [blame] | 27 | REQUEST = 0; |
Wyatt Hepler | 712d367 | 2020-07-13 15:52:11 -0700 | [diff] [blame] | 28 | |
Wyatt Hepler | 5ba8064 | 2021-06-18 12:56:17 -0700 | [diff] [blame] | 29 | // A message in a client stream. Always sent after a REQUEST and before a |
| 30 | // CLIENT_STREAM_END. |
Wyatt Hepler | a921116 | 2021-06-12 15:40:11 -0700 | [diff] [blame] | 31 | CLIENT_STREAM = 2; |
Wyatt Hepler | 0f26235 | 2020-07-29 09:51:27 -0700 | [diff] [blame] | 32 | |
| 33 | // The client received a packet for an RPC it did not request. |
| 34 | CLIENT_ERROR = 4; |
| 35 | |
Wyatt Hepler | a921116 | 2021-06-12 15:40:11 -0700 | [diff] [blame] | 36 | // The client requests cancellation of an ongoing RPC. |
| 37 | CANCEL = 6; |
| 38 | |
| 39 | // A client stream has completed. |
| 40 | CLIENT_STREAM_END = 8; |
Wyatt Hepler | 0f26235 | 2020-07-29 09:51:27 -0700 | [diff] [blame] | 41 | |
| 42 | // Server-to-client packets |
| 43 | |
Wyatt Hepler | 5ba8064 | 2021-06-18 12:56:17 -0700 | [diff] [blame] | 44 | // The RPC has finished. |
Wyatt Hepler | 0f26235 | 2020-07-29 09:51:27 -0700 | [diff] [blame] | 45 | RESPONSE = 1; |
| 46 | |
Wyatt Hepler | 5ba8064 | 2021-06-18 12:56:17 -0700 | [diff] [blame] | 47 | // Deprecated, do not use. Formerly was used as the last packet in a server |
| 48 | // stream. |
| 49 | DEPRECATED_SERVER_STREAM_END = 3; |
Wyatt Hepler | 0f26235 | 2020-07-29 09:51:27 -0700 | [diff] [blame] | 50 | |
| 51 | // The server was unable to process a request. |
| 52 | SERVER_ERROR = 5; |
Wyatt Hepler | 5ba8064 | 2021-06-18 12:56:17 -0700 | [diff] [blame] | 53 | |
| 54 | // A message in a server stream. |
| 55 | SERVER_STREAM = 7; |
Wyatt Hepler | af83568 | 2020-06-17 11:42:53 -0700 | [diff] [blame] | 56 | } |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 57 | |
| 58 | message RpcPacket { |
Wyatt Hepler | ba43a3c | 2020-08-13 12:45:25 -0700 | [diff] [blame] | 59 | // The type of packet. Determines which other fields are used. |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 60 | PacketType type = 1; |
| 61 | |
Wyatt Hepler | ba43a3c | 2020-08-13 12:45:25 -0700 | [diff] [blame] | 62 | // Channel through which the packet is sent. |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 63 | uint32 channel_id = 2; |
| 64 | |
Wyatt Hepler | 712d367 | 2020-07-13 15:52:11 -0700 | [diff] [blame] | 65 | // Hash of the fully-qualified name of the service with which this packet is |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 66 | // associated. For RPC packets, this is the service that processes the packet. |
Wyatt Hepler | 712d367 | 2020-07-13 15:52:11 -0700 | [diff] [blame] | 67 | fixed32 service_id = 3; |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 68 | |
Wyatt Hepler | 712d367 | 2020-07-13 15:52:11 -0700 | [diff] [blame] | 69 | // Hash of the name of the method which should process this packet. |
| 70 | fixed32 method_id = 4; |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 71 | |
Wyatt Hepler | 712d367 | 2020-07-13 15:52:11 -0700 | [diff] [blame] | 72 | // The packet's payload, which is an encoded protobuf. |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 73 | bytes payload = 5; |
Alexei Frolov | 0089094 | 2020-05-19 10:45:08 -0700 | [diff] [blame] | 74 | |
Wyatt Hepler | 712d367 | 2020-07-13 15:52:11 -0700 | [diff] [blame] | 75 | // Status code for the RPC response or error. |
Alexei Frolov | 0089094 | 2020-05-19 10:45:08 -0700 | [diff] [blame] | 76 | uint32 status = 6; |
Wyatt Hepler | af83568 | 2020-06-17 11:42:53 -0700 | [diff] [blame] | 77 | } |