• 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
38syntax = "proto2";
39
40package proto_util_converter.testing;
41
42import "google/protobuf/util/internal/testdata/anys.proto";
43
44// A book
45message Book {
46  optional string title = 1;
47  optional Author author = 2;
48  optional uint32 length = 3;
49  optional int64 published = 4;
50  optional bytes content = 5;
51
52  optional group Data = 6 {
53    optional uint32 year = 7;
54    optional string copyright = 8;
55  }
56
57  message Label {
58    optional string key = 1;
59    optional string value = 2;
60  }
61
62  optional Publisher publisher = 9;
63  repeated Label labels = 10;
64
65  enum Type {
66    FICTION = 1;
67    KIDS = 2;
68    ACTION_AND_ADVENTURE = 3;
69    arts_and_photography = 4;
70    I18N_Tech = 5;
71  }
72  optional Type type = 11;
73
74  // Useful for testing JSON snake/camel-case conversions.
75  optional string snake_field = 12;
76
77  // Used to test type not found in type info. Messages defined in other files
78  // are not added when adding Book to type info.
79  optional AnyWrapper type_not_found = 13;
80
81  // Used to test invalid value inside of primitive repeated fields.
82  repeated int32 primitive_repeated = 14;
83
84  extensions 200 to 499;
85}
86
87// A publisher of a book, tests required fields.
88message Publisher {
89  required string name = 1;
90}
91
92// An author of a book
93message Author {
94  optional uint64 id = 1 [json_name = "@id"];
95  optional string name = 2;
96  repeated string pseudonym = 3;
97  optional bool alive = 4;
98  repeated Author friend = 5;
99}
100
101// For testing resiliency of our protostream parser.
102// Field numbers of Author are reused for something else.
103message BadAuthor {
104  optional string id = 1;         // non-length-delimited to length-delimited.
105  repeated uint64 name = 2;       // string to repeated (both length-delimited).
106  optional string pseudonym = 3;  // Repeated to optional.
107  repeated bool alive = 4 [packed = true];  // Optional to repeated.
108}
109
110// All primitive types
111message Primitive {
112  // 32 bit numbers:
113  optional fixed32 fix32 = 1;
114  optional uint32 u32 = 2;
115  optional int32 i32 = 3;
116  optional sfixed32 sf32 = 4;
117  optional sint32 s32 = 5;
118
119  // 64 bit numbers:
120  optional fixed64 fix64 = 6;
121  optional uint64 u64 = 7;
122  optional int64 i64 = 8;
123  optional sfixed64 sf64 = 9;
124  optional sint64 s64 = 10;
125
126  // The other stuff.
127  optional string str = 11;
128  optional bytes bytes = 12;
129  optional float float = 13;
130  optional double double = 14;
131  optional bool bool = 15;
132
133  // repeated 32 bit numbers:
134  repeated fixed32 rep_fix32 = 16;
135  repeated uint32 rep_u32 = 17;
136  repeated int32 rep_i32 = 18;
137  repeated sfixed32 rep_sf32 = 19;
138  repeated sint32 rep_s32 = 20;
139
140  // repeated 64 bit numbers:
141  repeated fixed64 rep_fix64 = 21;
142  repeated uint64 rep_u64 = 22;
143  repeated int64 rep_i64 = 23;
144  repeated sfixed64 rep_sf64 = 24;
145  repeated sint64 rep_s64 = 25;
146
147  // repeated other stuff:
148  repeated string rep_str = 26;
149  repeated bytes rep_bytes = 27;
150  repeated float rep_float = 28;
151  repeated double rep_double = 29;
152  repeated bool rep_bool = 30;
153}
154
155// Test packed versions of all repeated primitives.
156// The field numbers should match their non-packed version in Primitive message.
157message PackedPrimitive {
158  // repeated 32 bit numbers:
159  repeated fixed32 rep_fix32 = 16 [packed = true];
160  repeated uint32 rep_u32 = 17 [packed = true];
161  repeated int32 rep_i32 = 18 [packed = true];
162  repeated sfixed32 rep_sf32 = 19 [packed = true];
163  repeated sint32 rep_s32 = 20 [packed = true];
164
165  // repeated 64 bit numbers:
166  repeated fixed64 rep_fix64 = 21 [packed = true];
167  repeated uint64 rep_u64 = 22 [packed = true];
168  repeated int64 rep_i64 = 23 [packed = true];
169  repeated sfixed64 rep_sf64 = 24 [packed = true];
170  repeated sint64 rep_s64 = 25 [packed = true];
171
172  // repeated other stuff:
173  repeated float rep_float = 28 [packed = true];
174  repeated double rep_double = 29 [packed = true];
175  repeated bool rep_bool = 30 [packed = true];
176}
177
178// Test extensions.
179extend Book {
180  repeated Author more_author = 201;
181}
182
183// Test nested extensions.
184message NestedBook {
185  extend Book {
186    optional NestedBook another_book = 301;
187  }
188  // Recurse
189  optional Book book = 1;
190}
191
192// For testing resiliency of our protostream parser.
193// Field number of NestedBook is reused for something else.
194message BadNestedBook {
195  repeated uint32 book = 1 [packed = true];  // Packed to optional message.
196}
197
198// A recursively defined message.
199message Cyclic {
200  optional int32 m_int = 1;
201  optional string m_str = 2;
202  optional Book m_book = 3;
203  repeated Author m_author = 5;
204  optional Cyclic m_cyclic = 4;
205}
206
207// Test that two messages can have different fields mapped to the same JSON
208// name. See: https://github.com/protocolbuffers/protobuf/issues/1415
209message TestJsonName1 {
210  optional int32 one_value = 1 [json_name = "value"];
211}
212message TestJsonName2 {
213  optional int32 another_value = 1 [json_name = "value"];
214}
215