• 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.
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  enum Type {
60    FICTION = 1;
61    KIDS = 2;
62    ACTION_AND_ADVENTURE = 3;
63  }
64  optional Type type = 11;
65
66  extensions 200 to 499;
67}
68
69// A publisher of a book, tests required fields.
70message Publisher {
71  required string name = 1;
72}
73
74// An author of a book
75message Author {
76  optional uint64 id = 1 [json_name = "@id"];
77  optional string name = 2;
78  repeated string pseudonym = 3;
79  optional bool alive = 4;
80  repeated Author friend = 5;
81}
82
83// For testing resiliency of our protostream parser.
84// Field numbers of Author are reused for something else.
85message BadAuthor {
86  optional string id = 1;  // non-length-delimited to length-delimited.
87  repeated uint64 name = 2;  // string to repeated (both length-delimited).
88  optional string pseudonym = 3;  // Repeated to optional.
89  repeated bool alive = 4 [packed=true];  // Optional to repeated.
90}
91
92// All primitive types
93message Primitive {
94  // 32 bit numbers:
95  optional fixed32 fix32 = 1;
96  optional uint32 u32 = 2;
97  optional int32 i32 = 3;
98  optional sfixed32 sf32 = 4;
99  optional sint32 s32 = 5;
100
101  // 64 bit numbers:
102  optional fixed64 fix64 = 6;
103  optional uint64 u64 = 7;
104  optional int64 i64 = 8;
105  optional sfixed64 sf64 = 9;
106  optional sint64 s64 = 10;
107
108  // The other stuff.
109  optional string str = 11;
110  optional bytes bytes = 12;
111  optional float float = 13;
112  optional double double = 14;
113  optional bool bool = 15;
114
115  // repeated 32 bit numbers:
116  repeated fixed32 rep_fix32 = 16;
117  repeated uint32 rep_u32 = 17;
118  repeated int32 rep_i32 = 18;
119  repeated sfixed32 rep_sf32 = 19;
120  repeated sint32 rep_s32 = 20;
121
122  // repeated 64 bit numbers:
123  repeated fixed64 rep_fix64 = 21;
124  repeated uint64 rep_u64 = 22;
125  repeated int64 rep_i64 = 23;
126  repeated sfixed64 rep_sf64 = 24;
127  repeated sint64 rep_s64 = 25;
128
129  // repeated other stuff:
130  repeated string rep_str = 26;
131  repeated bytes rep_bytes = 27;
132  repeated float rep_float = 28;
133  repeated double rep_double = 29;
134  repeated bool rep_bool = 30;
135}
136
137// Test packed versions of all repeated primitives.
138// The field numbers should match their non-packed version in Primitive message.
139message PackedPrimitive {
140  // repeated 32 bit numbers:
141  repeated fixed32 rep_fix32 = 16 [packed=true];
142  repeated uint32 rep_u32 = 17 [packed=true];
143  repeated int32 rep_i32 = 18 [packed=true];
144  repeated sfixed32 rep_sf32 = 19 [packed=true];
145  repeated sint32 rep_s32 = 20 [packed=true];
146
147  // repeated 64 bit numbers:
148  repeated fixed64 rep_fix64 = 21 [packed=true];
149  repeated uint64 rep_u64 = 22 [packed=true];
150  repeated int64 rep_i64 = 23 [packed=true];
151  repeated sfixed64 rep_sf64 = 24 [packed=true];
152  repeated sint64 rep_s64 = 25 [packed=true];
153
154  // repeated other stuff:
155  repeated float rep_float = 28 [packed=true];
156  repeated double rep_double = 29 [packed=true];
157  repeated bool rep_bool = 30 [packed=true];
158}
159
160// Test extensions.
161extend Book {
162  repeated Author more_author = 201;
163}
164
165// Test nested extensions.
166message NestedBook {
167  extend Book {
168    optional NestedBook another_book = 301;
169  }
170  // Recurse
171  optional Book book = 1;
172}
173
174// For testing resiliency of our protostream parser.
175// Field number of NestedBook is reused for something else.
176message BadNestedBook {
177  repeated uint32 book = 1 [packed=true];  // Packed to optional message.
178}
179
180// A recursively defined message.
181message Cyclic {
182  optional int32 m_int = 1;
183  optional string m_str = 2;
184  optional Book m_book = 3;
185  repeated Author m_author = 5;
186  optional Cyclic m_cyclic = 4;
187}
188