books.proto 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. // Author: sven@google.com (Sven Mawson)
  31. //
  32. // Sample protos for testing.
  33. // Some of the older enums don't use CAPITALS_WITH_UNDERSCORES for testing.
  34. // LINT: LEGACY_NAMES
  35. syntax = "proto2";
  36. package google.protobuf.testing;
  37. // A book
  38. message Book {
  39. optional string title = 1;
  40. optional Author author = 2;
  41. optional uint32 length = 3;
  42. optional int64 published = 4;
  43. optional bytes content = 5;
  44. optional group Data = 6 {
  45. optional uint32 year = 7;
  46. optional string copyright = 8;
  47. }
  48. message Label {
  49. optional string key = 1;
  50. optional string value = 2;
  51. }
  52. optional Publisher publisher = 9;
  53. repeated Label labels = 10;
  54. enum Type {
  55. FICTION = 1;
  56. KIDS = 2;
  57. ACTION_AND_ADVENTURE = 3;
  58. arts_and_photography = 4;
  59. I18N_Tech = 5;
  60. }
  61. optional Type type = 11;
  62. extensions 200 to 499;
  63. }
  64. // A publisher of a book, tests required fields.
  65. message Publisher {
  66. required string name = 1;
  67. }
  68. // An author of a book
  69. message Author {
  70. optional uint64 id = 1 [json_name = "@id"];
  71. optional string name = 2;
  72. repeated string pseudonym = 3;
  73. optional bool alive = 4;
  74. repeated Author friend = 5;
  75. }
  76. // For testing resiliency of our protostream parser.
  77. // Field numbers of Author are reused for something else.
  78. message 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. // All primitive types
  85. message Primitive {
  86. // 32 bit numbers:
  87. optional fixed32 fix32 = 1;
  88. optional uint32 u32 = 2;
  89. optional int32 i32 = 3;
  90. optional sfixed32 sf32 = 4;
  91. optional sint32 s32 = 5;
  92. // 64 bit numbers:
  93. optional fixed64 fix64 = 6;
  94. optional uint64 u64 = 7;
  95. optional int64 i64 = 8;
  96. optional sfixed64 sf64 = 9;
  97. optional sint64 s64 = 10;
  98. // The other stuff.
  99. optional string str = 11;
  100. optional bytes bytes = 12;
  101. optional float float = 13;
  102. optional double double = 14;
  103. optional bool bool = 15;
  104. // repeated 32 bit numbers:
  105. repeated fixed32 rep_fix32 = 16;
  106. repeated uint32 rep_u32 = 17;
  107. repeated int32 rep_i32 = 18;
  108. repeated sfixed32 rep_sf32 = 19;
  109. repeated sint32 rep_s32 = 20;
  110. // repeated 64 bit numbers:
  111. repeated fixed64 rep_fix64 = 21;
  112. repeated uint64 rep_u64 = 22;
  113. repeated int64 rep_i64 = 23;
  114. repeated sfixed64 rep_sf64 = 24;
  115. repeated sint64 rep_s64 = 25;
  116. // repeated other stuff:
  117. repeated string rep_str = 26;
  118. repeated bytes rep_bytes = 27;
  119. repeated float rep_float = 28;
  120. repeated double rep_double = 29;
  121. repeated bool rep_bool = 30;
  122. }
  123. // Test packed versions of all repeated primitives.
  124. // The field numbers should match their non-packed version in Primitive message.
  125. message PackedPrimitive {
  126. // repeated 32 bit numbers:
  127. repeated fixed32 rep_fix32 = 16 [packed=true];
  128. repeated uint32 rep_u32 = 17 [packed=true];
  129. repeated int32 rep_i32 = 18 [packed=true];
  130. repeated sfixed32 rep_sf32 = 19 [packed=true];
  131. repeated sint32 rep_s32 = 20 [packed=true];
  132. // repeated 64 bit numbers:
  133. repeated fixed64 rep_fix64 = 21 [packed=true];
  134. repeated uint64 rep_u64 = 22 [packed=true];
  135. repeated int64 rep_i64 = 23 [packed=true];
  136. repeated sfixed64 rep_sf64 = 24 [packed=true];
  137. repeated sint64 rep_s64 = 25 [packed=true];
  138. // repeated other stuff:
  139. repeated float rep_float = 28 [packed=true];
  140. repeated double rep_double = 29 [packed=true];
  141. repeated bool rep_bool = 30 [packed=true];
  142. }
  143. // Test extensions.
  144. extend Book {
  145. repeated Author more_author = 201;
  146. }
  147. // Test nested extensions.
  148. message NestedBook {
  149. extend Book {
  150. optional NestedBook another_book = 301;
  151. }
  152. // Recurse
  153. optional Book book = 1;
  154. }
  155. // For testing resiliency of our protostream parser.
  156. // Field number of NestedBook is reused for something else.
  157. message BadNestedBook {
  158. repeated uint32 book = 1 [packed=true]; // Packed to optional message.
  159. }
  160. // A recursively defined message.
  161. message Cyclic {
  162. optional int32 m_int = 1;
  163. optional string m_str = 2;
  164. optional Book m_book = 3;
  165. repeated Author m_author = 5;
  166. optional Cyclic m_cyclic = 4;
  167. }
  168. // Test that two messages can have different fields mapped to the same JSON
  169. // name. See: https://github.com/google/protobuf/issues/1415
  170. message TestJsonName1 {
  171. optional int32 one_value = 1 [json_name = "value"];
  172. }
  173. message TestJsonName2 {
  174. optional int32 another_value = 1 [json_name = "value"];
  175. }