• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc.  All rights reserved.
3// https://developers.google.com/protocol-buffers/
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9//     * Redistributions of source code must retain the above copyright
10// notice, this list of conditions and the following disclaimer.
11//     * Redistributions in binary form must reproduce the above
12// copyright notice, this list of conditions and the following disclaimer
13// in the documentation and/or other materials provided with the
14// distribution.
15//     * Neither the name of Google Inc. nor the names of its
16// contributors may be used to endorse or promote products derived from
17// this software without specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31// Author: sven@google.com (Sven Mawson)
32//
33// Sample protos for testing.
34
35// Some of the older enums don't use CAPITALS_WITH_UNDERSCORES for testing.
36// LINT: LEGACY_NAMES
37// LINT: ALLOW_GROUPS
38
39syntax = "proto2";
40
41package proto_util_converter.testing;
42
43import "google/protobuf/util/internal/testdata/anys.proto";
44
45// A book
46message Book {
47  optional string title = 1;
48  optional Author author = 2;
49  optional uint32 length = 3;
50  optional int64 published = 4;
51  optional bytes content = 5;
52
53  optional group Data = 6 {
54    optional uint32 year = 7;
55    optional string copyright = 8;
56  }
57
58  message Label {
59    optional string key = 1;
60    optional string value = 2;
61  }
62
63  optional Publisher publisher = 9;
64  repeated Label labels = 10;
65
66  enum Type {
67    FICTION = 1;
68    KIDS = 2;
69    ACTION_AND_ADVENTURE = 3;
70    arts_and_photography = 4;
71    I18N_Tech = 5;
72  }
73  optional Type type = 11;
74
75  // Useful for testing JSON snake/camel-case conversions.
76  optional string snake_field = 12;
77
78  // Used to test type not found in type info. Messages defined in other files
79  // are not added when adding Book to type info.
80  optional AnyWrapper type_not_found = 13;
81
82  // Used to test invalid value inside of primitive repeated fields.
83  repeated int32 primitive_repeated = 14;
84
85  extensions 200 to 499;
86}
87
88// A publisher of a book, tests required fields.
89message Publisher {
90  required string name = 1;
91}
92
93// An author of a book
94message Author {
95  optional uint64 id = 1 [json_name = "@id"];
96  optional string name = 2;
97  repeated string pseudonym = 3;
98  optional bool alive = 4;
99  repeated Author friend = 5;
100}
101
102// For testing resiliency of our protostream parser.
103// Field numbers of Author are reused for something else.
104message BadAuthor {
105  optional string id = 1;         // non-length-delimited to length-delimited.
106  repeated uint64 name = 2;       // string to repeated (both length-delimited).
107  optional string pseudonym = 3;  // Repeated to optional.
108  repeated bool alive = 4 [packed = true];  // Optional to repeated.
109}
110
111// All primitive types
112message Primitive {
113  // 32 bit numbers:
114  optional fixed32 fix32 = 1;
115  optional uint32 u32 = 2;
116  optional int32 i32 = 3;
117  optional sfixed32 sf32 = 4;
118  optional sint32 s32 = 5;
119
120  // 64 bit numbers:
121  optional fixed64 fix64 = 6;
122  optional uint64 u64 = 7;
123  optional int64 i64 = 8;
124  optional sfixed64 sf64 = 9;
125  optional sint64 s64 = 10;
126
127  // The other stuff.
128  optional string str = 11;
129  optional bytes bytes = 12;
130  optional float float = 13;
131  optional double double = 14;
132  optional bool bool = 15;
133
134  // repeated 32 bit numbers:
135  repeated fixed32 rep_fix32 = 16;
136  repeated uint32 rep_u32 = 17;
137  repeated int32 rep_i32 = 18;
138  repeated sfixed32 rep_sf32 = 19;
139  repeated sint32 rep_s32 = 20;
140
141  // repeated 64 bit numbers:
142  repeated fixed64 rep_fix64 = 21;
143  repeated uint64 rep_u64 = 22;
144  repeated int64 rep_i64 = 23;
145  repeated sfixed64 rep_sf64 = 24;
146  repeated sint64 rep_s64 = 25;
147
148  // repeated other stuff:
149  repeated string rep_str = 26;
150  repeated bytes rep_bytes = 27;
151  repeated float rep_float = 28;
152  repeated double rep_double = 29;
153  repeated bool rep_bool = 30;
154}
155
156// Test packed versions of all repeated primitives.
157// The field numbers should match their non-packed version in Primitive message.
158message PackedPrimitive {
159  // repeated 32 bit numbers:
160  repeated fixed32 rep_fix32 = 16 [packed = true];
161  repeated uint32 rep_u32 = 17 [packed = true];
162  repeated int32 rep_i32 = 18 [packed = true];
163  repeated sfixed32 rep_sf32 = 19 [packed = true];
164  repeated sint32 rep_s32 = 20 [packed = true];
165
166  // repeated 64 bit numbers:
167  repeated fixed64 rep_fix64 = 21 [packed = true];
168  repeated uint64 rep_u64 = 22 [packed = true];
169  repeated int64 rep_i64 = 23 [packed = true];
170  repeated sfixed64 rep_sf64 = 24 [packed = true];
171  repeated sint64 rep_s64 = 25 [packed = true];
172
173  // repeated other stuff:
174  repeated float rep_float = 28 [packed = true];
175  repeated double rep_double = 29 [packed = true];
176  repeated bool rep_bool = 30 [packed = true];
177}
178
179// Test extensions.
180extend Book {
181  repeated Author more_author = 201;
182}
183
184// Test nested extensions.
185message NestedBook {
186  extend Book {
187    optional NestedBook another_book = 301;
188  }
189  // Recurse
190  optional Book book = 1;
191}
192
193// For testing resiliency of our protostream parser.
194// Field number of NestedBook is reused for something else.
195message BadNestedBook {
196  repeated uint32 book = 1 [packed = true];  // Packed to optional message.
197}
198
199// A recursively defined message.
200message Cyclic {
201  optional int32 m_int = 1;
202  optional string m_str = 2;
203  optional Book m_book = 3;
204  repeated Author m_author = 5;
205  optional Cyclic m_cyclic = 4;
206}
207
208// Test that two messages can have different fields mapped to the same JSON
209// name. See: https://github.com/protocolbuffers/protobuf/issues/1415
210message TestJsonName1 {
211  optional int32 one_value = 1 [json_name = "value"];
212}
213message TestJsonName2 {
214  optional int32 another_value = 1 [json_name = "value"];
215}
216
217message TestPrimitiveFieldsWithSameJsonName {
218  optional string val_str1 = 1;
219  optional string val_str_1 = 2;
220
221  optional int32 val_int321 = 3;
222  optional int32 val_int32_1 = 4;
223
224  optional uint32 val_uint321 = 5;
225  optional uint32 val_uint32_1 = 6;
226
227  optional int64 val_int641 = 7;
228  optional int64 val_int64_1 = 8;
229
230  optional uint64 val_uint641 = 9;
231  optional uint64 val_uint64_1 = 10;
232
233  optional bool val_bool1 = 11;
234  optional bool val_bool_1 = 12;
235
236  optional double val_double1 = 13;
237  optional double val_double_1 = 14;
238
239  optional float val_float1 = 15;
240  optional float val_float_1 = 16;
241}
242
243message TestRepeatedFieldsWithSameJsonName {
244  repeated string rep_str1 = 1;
245  repeated string rep_str_1 = 2;
246}
247
248message TestMessageFieldsWithSameJsonName {
249  optional Primitive prim1 = 1;
250  optional Primitive prim_1 = 2;
251}
252