-
Notifications
You must be signed in to change notification settings - Fork 36
/
piqi.protobuf.piqi
286 lines (215 loc) · 5.52 KB
/
piqi.protobuf.piqi
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
% Copyright 2009, 2010, 2011, 2012, 2013, 2017, 2018 Anton Lavrik
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
% Google Protocol Buffers extension for Piqi self-spec
%
% This file defines two kinds of extensions to the base Piqi self-specification:
%
% - properties related to Protocol Buffer's .proto files that are used by
% "piqi to-proto" command
%
% - properties related to binary binary Google Protocol Buffers format also
% known as wire format
%
%
% The document describing Protocol Buffers binary "wire" format:
%
% https://developers.google.com/protocol-buffers/docs/encoding
.protobuf-package "piqi_org.piqi"
.include [ .module piqi ]
%
% mapping between Piqi primitive and Protobuf types
%
.extend [
.typedef int
.with.protobuf-type "sint32"
.with.protobuf-wire-type.zigzag-varint
]
.extend [
.typedef uint
.with.protobuf-type "uint32"
.with.protobuf-wire-type.varint
]
.extend [
.typedef int32
.with.protobuf-type "sint32"
.with.protobuf-wire-type.zigzag-varint
]
.extend [
.typedef uint32
.with.protobuf-type "uint32"
.with.protobuf-wire-type.varint
]
.extend [
.typedef int64
.with.protobuf-type "sint64"
.with.protobuf-wire-type.zigzag-varint
]
.extend [
.typedef uint64
.with.protobuf-type "uint64"
.with.protobuf-wire-type.varint
]
.extend [
.typedef int32-fixed
.with.protobuf-type "sfixed32"
.with.protobuf-wire-type.signed-fixed32
]
.extend [
.typedef uint32-fixed
.with.protobuf-type "fixed32"
.with.protobuf-wire-type.fixed32
]
.extend [
.typedef int64-fixed
.with.protobuf-type "sfixed64"
.with.protobuf-wire-type.signed-fixed64
]
.extend [
.typedef uint64-fixed
.with.protobuf-type "fixed64"
.with.protobuf-wire-type.fixed64
]
.extend [
.typedef float64
.with.protobuf-type "double"
.with.protobuf-wire-type.fixed64
]
.extend [
.typedef float32
.with.protobuf-type "float"
.with.protobuf-wire-type.fixed32
]
% These two types are specific to Protocol Buffers. They have the same
% on-the-wire representation as uint32/64. The difference is that they allow
% negative integers (which representation is very inefficient requiring many
% bytes for small absolue values).
.alias [
.name protobuf-int32
.type int32
.piqi-type.int
.protobuf-type "int32"
.protobuf-wire-type.signed-varint
]
.alias [
.name protobuf-int64
.type int64
.piqi-type.int
.protobuf-type "int64"
.protobuf-wire-type.signed-varint
]
%
% properties specific to .piqi to .proto conversion
%
.extend [
.typedef* [ record field variant option enum alias list ]
.with.field [
.name protobuf-name
.type string
.optional
]
]
.extend [
.typedef* [ piqi record variant list enum ]
.with.field [
% arbitrary string that will be included in .proto message and enum
% definitions as a result of .piqi -> .proto conversion
.name protobuf-custom
.type string
.repeated
]
]
.extend [
.typedef piqi
.with.field [
.name protobuf-package
.type string
.optional
]
]
.extend [
.typedef alias
.with.field [
.name protobuf-type
.type string
.optional
]
]
.extend [
.typedef enum
.with.field [
% prefix each enum option's name with the specified string; it helps to
% deal with the fact that enum doesn't form a C++ namespace meaning that
% enum constants are defined directly in the outer namespace; it was
% announced that this problem will be fixed in protobuf-2.5
.name protobuf-prefix
.type string
.optional
]
]
%
% definitions and extensions related to how data is represented on the wire
%
.enum [
.name protobuf-wire-type
.option [ varint ]
.option [ zigzag-varint ]
.option [ fixed32 ]
.option [ fixed64 ]
.option [ signed-varint ]
.option [ signed-fixed32 ]
.option [ signed-fixed64 ]
.option [ block ]
]
.extend [
.typedef alias
.with.field [
.type protobuf-wire-type
.optional
]
]
.extend [
.typedef* [ field option ]
.with.field [
% for fields and variant options: unique integer field id
% from (1 -- (2^29-1)) range used for identifying individual fields and
% options encoded in wire format
%
% for enum options: non-unique integer constant from a full int32 range
.name code
.type int32
.optional
]
]
.extend [
.typedef* [ field list ]
% indication that Protobuf "packed" format is used for repeated fields or
% list elements
.with.field [
.name protobuf-packed
.optional
]
]
.extend [
.typedef variant
% specifies the name for the protobuf "oneof", when present "piqi to-proto"
% wraps all variant options into protobuf's oneof construct:
%
% oneof <name> { <options> }
%
.with.field [
.name protobuf-oneof
.type string
.optional
]
]