blob: 82b8176066f4c546ff70a66360bc1da2ca39a5a6 [file] [log] [blame]
Feng Xiaoe96ff302015-06-15 18:21:48 -07001// 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.
34syntax = "proto2";
35
36package google.protobuf.testing;
37
38// A book
39message Book {
40 optional string title = 1;
41 optional Author author = 2;
42 optional uint32 length = 3;
43 optional int64 published = 4;
44 optional bytes content = 5;
45
46 optional group Data = 6 {
47 optional uint32 year = 7;
48 optional string copyright = 8;
49 }
50
51 message Label {
52 optional string key = 1;
53 optional string value = 2;
54 }
55
56 optional Publisher publisher = 9;
57 repeated Label labels = 10;
58
59 extensions 200 to 499;
60}
61
62// A publisher of a book, tests required fields.
63message Publisher {
64 required string name = 1;
65}
66
67// An author of a book
68message Author {
Feng Xiaoe841bac2015-12-11 17:09:20 -080069 optional uint64 id = 1 [json_name = "@id"];
Feng Xiaoe96ff302015-06-15 18:21:48 -070070 optional string name = 2;
71 repeated string pseudonym = 3;
72 optional bool alive = 4;
73 repeated Author friend = 5;
74}
75
76// For testing resiliency of our protostream parser.
77// Field numbers of Author are reused for something else.
78message BadAuthor {
79 optional string id = 1; // non-length-delimited to length-delimited.
80 repeated uint64 name = 2; // string to repeated (both length-delimited).
81 optional string pseudonym = 3; // Repeated to optional.
82 repeated bool alive = 4 [packed=true]; // Optional to repeated.
83}
84
85// All primitive types
86message Primitive {
87 // 32 bit numbers:
88 optional fixed32 fix32 = 1;
89 optional uint32 u32 = 2;
90 optional int32 i32 = 3;
91 optional sfixed32 sf32 = 4;
92 optional sint32 s32 = 5;
93
94 // 64 bit numbers:
95 optional fixed64 fix64 = 6;
96 optional uint64 u64 = 7;
97 optional int64 i64 = 8;
98 optional sfixed64 sf64 = 9;
99 optional sint64 s64 = 10;
100
101 // The other stuff.
102 optional string str = 11;
103 optional bytes bytes = 12;
104 optional float float = 13;
105 optional double double = 14;
106 optional bool bool = 15;
107
108 // repeated 32 bit numbers:
109 repeated fixed32 rep_fix32 = 16;
110 repeated uint32 rep_u32 = 17;
111 repeated int32 rep_i32 = 18;
112 repeated sfixed32 rep_sf32 = 19;
113 repeated sint32 rep_s32 = 20;
114
115 // repeated 64 bit numbers:
116 repeated fixed64 rep_fix64 = 21;
117 repeated uint64 rep_u64 = 22;
118 repeated int64 rep_i64 = 23;
119 repeated sfixed64 rep_sf64 = 24;
120 repeated sint64 rep_s64 = 25;
121
122 // repeated other stuff:
123 repeated string rep_str = 26;
124 repeated bytes rep_bytes = 27;
125 repeated float rep_float = 28;
126 repeated double rep_double = 29;
127 repeated bool rep_bool = 30;
128}
129
130// Test packed versions of all repeated primitives.
131// The field numbers should match their non-packed version in Primitive message.
132message PackedPrimitive {
133 // repeated 32 bit numbers:
134 repeated fixed32 rep_fix32 = 16 [packed=true];
135 repeated uint32 rep_u32 = 17 [packed=true];
136 repeated int32 rep_i32 = 18 [packed=true];
137 repeated sfixed32 rep_sf32 = 19 [packed=true];
138 repeated sint32 rep_s32 = 20 [packed=true];
139
140 // repeated 64 bit numbers:
141 repeated fixed64 rep_fix64 = 21 [packed=true];
142 repeated uint64 rep_u64 = 22 [packed=true];
143 repeated int64 rep_i64 = 23 [packed=true];
144 repeated sfixed64 rep_sf64 = 24 [packed=true];
145 repeated sint64 rep_s64 = 25 [packed=true];
146
147 // repeated other stuff:
148 repeated float rep_float = 28 [packed=true];
149 repeated double rep_double = 29 [packed=true];
150 repeated bool rep_bool = 30 [packed=true];
151}
152
153// Test extensions.
154extend Book {
155 repeated Author more_author = 201;
156}
157
158// Test nested extensions.
159message NestedBook {
160 extend Book {
161 optional NestedBook another_book = 301;
162 }
163 // Recurse
164 optional Book book = 1;
165}
166
167// For testing resiliency of our protostream parser.
168// Field number of NestedBook is reused for something else.
169message BadNestedBook {
170 repeated uint32 book = 1 [packed=true]; // Packed to optional message.
171}