-
Notifications
You must be signed in to change notification settings - Fork 5
/
cannyls_rpc.proto
156 lines (130 loc) · 4.05 KB
/
cannyls_rpc.proto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
///
/// CannylsのRPC用のスキーマ定義
///
syntax = "proto3";
// https://github.com/google/protobuf/blob/master/src/google/protobuf/duration.proto
import "google/protobuf/duration.proto";
// https://github.com/sile/protobuf_codec/blob/master/protobuf/trackable.proto
import "protobuf_codec/protobuf/trackable.proto";
package cannyls_rpc.protobuf;
// 128ビット幅のLumpId.
message LumpId {
// 上位64ビット.
fixed64 high = 1;
// 下位64ビット.
fixed64 low = 2;
}
/// リクエスト処理のデッドライン(優先順位).
message Deadline {
enum Type {
INFINITY = 0;
WITHIN = 1;
IMMEDIATE = 2;
}
Type type = 1;
// デッドラインまでの残り時間(現在時刻からの相対時間).
//
// `type=WITHIN`の場合以外には、存在していても無視される.
//
// 省略時には「0秒」として扱われる.
// また、秒ないしナノ秒部分が負数、の場合にはエラー扱いとなる.
google.protobuf.Duration duration = 2;
}
// RPCリクエストのオプション.
message RequestOptions {
// リクエスト処理のデッドライン(優先順位).
//
// 省略された場合には`Deadline::Infinity`として扱われる.
Deadline deadline = 1;
// デバイスのコマンドのキューの長さ制限.
//
// リクエスト処理時に、対象デバイスのキューの長さがこの値に達している場合には、Busyエラーが返される.
//
// なお値が`0`の場合には「無制限」とみなされる.
uint32 queue_size_limit = 2;
}
// Lumpに対するリクエスト(PUT以外).
message LumpRequest {
// 対象デバイスのID.
string device_id = 1;
// 対象lumpのID.
LumpId lump_id = 2;
// オプション.
RequestOptions options = 3;
}
// LumpのPUTリクエスト.
message PutLumpRequest {
// 対象デバイスのID.
string device_id = 1;
// 対象lumpのID.
LumpId lump_id = 2;
// Lumpのデータ.
bytes lump_data = 3;
// オプション.
RequestOptions options = 4;
}
// `GetLumpRpc`の応答.
message GeLumpResponse {
// 対象lumpが存在しない場合には、フィールドが省略される.
oneof result {
bytes lump_data = 1;
Error error = 2;
}
}
// `HeadLumpRpc`の応答.
message HeadLumpResponse {
// 対象lumpが存在しない場合には、フィールドが省略される.
oneof result {
uint32 approximate_data_size = 1; // lumpのデータサイズの近似値
Error error = 2;
}
}
// `PutLumpRpc`の応答.
message PutLumpResponse {
oneof result {
bool created = 1; // 新規作成なら`true`、上書きなら`false`
Error error = 2;
}
}
// `DeleteLumpRpc`の応答.
message DeleteLumpResponse {
oneof result {
bool deleted = 1; // 削除されたなら`true`、存在しなかったなら`false`
Error error = 2;
}
}
// デバイスに対するリクエスト.
message DeviceRequest {
// 対象デバイスのID.
string device_id = 1;
// オプション.
RequestOptions options = 2;
}
// `ListLumpRpc`の応答.
//
// [NOTE]
//
// `oneof`を使っていないのは、それが`repeated`と直接は組み合わせられないため.
//
// 現状のRustライブラリの実装上、一段メッセージを挟んで`repeated`(と`oneof`)を
// 使うようにすると(送信時に)無駄なメモリコピーが発生してしまう.
//
// lumpの数は多い場合には数千万以上となることが予想され、
// 無視できないコストとなる可能性があるので、
// この応答メッセージに関しては、フラットな構造となるようにした.
message ListLumpResponse {
// 対象デバイスが保持するlumpのID一覧.
//
// エラー発生時には空となる.
repeated LumpId lump_ids = 1;
// エラー情報.
//
// 成功応答時には省略される.
Error error = 2;
}
// `cannyls`固有のエラーメッセージ.
//
// `kind`フィールドの値として`cannyls::ErrorKind`の文字列表現を保持する.
message Error {
protobuf_codec.protobuf.trackable.Error error = 1;
}