Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame^] | 1 | // Copyright 2018 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // Test Protobuf definitions with proto2 syntax. |
| 6 | syntax = "proto2"; |
| 7 | |
| 8 | package pb2; |
| 9 | option go_package = "github.com/golang/protobuf/v2/encoding/textpb/testprotos/pb2"; |
| 10 | |
| 11 | import "google/protobuf/any.proto"; |
| 12 | import "google/protobuf/empty.proto"; |
| 13 | import "google/protobuf/duration.proto"; |
| 14 | import "google/protobuf/struct.proto"; |
| 15 | import "google/protobuf/timestamp.proto"; |
| 16 | import "google/protobuf/wrappers.proto"; |
| 17 | |
| 18 | // Scalars contains optional scalar fields. |
| 19 | message Scalars { |
| 20 | optional bool opt_bool = 1; |
| 21 | |
| 22 | optional int32 opt_int32 = 2; |
| 23 | optional int64 opt_int64 = 3; |
| 24 | optional uint32 opt_uint32 = 4; |
| 25 | optional uint64 opt_uint64 = 5; |
| 26 | optional sint32 opt_sint32 = 6; |
| 27 | optional sint64 opt_sint64 = 7; |
| 28 | optional fixed32 opt_fixed32 = 8; |
| 29 | optional fixed64 opt_fixed64 = 9; |
| 30 | optional sfixed32 opt_sfixed32 = 10; |
| 31 | optional sfixed64 opt_sfixed64 = 11; |
| 32 | |
| 33 | optional float opt_float = 20; |
| 34 | optional double opt_double = 21; |
| 35 | |
| 36 | optional bytes opt_bytes = 14; |
| 37 | optional string opt_string = 13; |
| 38 | } |
| 39 | |
| 40 | // Message contains repeated fields. |
| 41 | message Repeats { |
| 42 | repeated bool rpt_bool = 1; |
| 43 | repeated int32 rpt_int32 = 2; |
| 44 | repeated int64 rpt_int64 = 3; |
| 45 | repeated uint32 rpt_uint32 = 4; |
| 46 | repeated uint64 rpt_uint64 = 5; |
| 47 | repeated float rpt_float = 6; |
| 48 | repeated double rpt_double = 7; |
| 49 | repeated string rpt_string = 15; |
| 50 | repeated bytes rpt_bytes = 14; |
| 51 | } |
| 52 | |
| 53 | enum Enum { |
| 54 | UNKNOWN = 0; |
| 55 | FIRST = 1; |
| 56 | SECOND = 2; |
| 57 | TENTH = 10; |
| 58 | } |
| 59 | |
| 60 | // Message contains enum fields. |
| 61 | message Enums { |
| 62 | optional Enum opt_enum = 1; |
| 63 | repeated Enum rpt_enum = 2; |
| 64 | |
| 65 | enum NestedEnum { |
| 66 | UNO = 1; |
| 67 | DOS = 2; |
| 68 | DIEZ = 10; |
| 69 | } |
| 70 | optional NestedEnum opt_nested_enum = 3; |
| 71 | repeated NestedEnum rpt_nested_enum = 4; |
| 72 | } |
| 73 | |
| 74 | // Message contains message and group fields. |
| 75 | message Nests { |
| 76 | optional Nested opt_nested = 1; |
| 77 | optional group OptGroup = 2 { |
| 78 | optional bool opt_bool = 1; |
| 79 | optional string opt_string = 2; |
| 80 | optional Nested opt_nested = 3; |
| 81 | |
| 82 | optional group OptNestedGroup = 4 { |
| 83 | optional Enum opt_enum = 1; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | repeated Nested rpt_nested = 3; |
| 88 | repeated group RptGroup = 4 { |
| 89 | repeated bool rpt_bool = 1; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // Message type used as submessage. |
| 94 | message Nested { |
| 95 | optional string opt_string = 1; |
| 96 | optional Nested opt_nested = 2; |
| 97 | } |
| 98 | |
| 99 | // Message contains required fields. |
| 100 | message Requireds { |
| 101 | required bool req_bool = 1; |
| 102 | required fixed32 req_fixed32 = 2; |
| 103 | required fixed64 req_fixed64 = 3; |
| 104 | required sfixed32 req_sfixed32 = 4; |
| 105 | required sfixed64 req_sfixed64 = 5; |
| 106 | required float req_float = 6; |
| 107 | required double req_double = 7; |
| 108 | required string req_string = 8; |
| 109 | required bytes req_bytes = 9; |
| 110 | required Enum req_enum = 10; |
| 111 | required Nested req_nested = 11; |
| 112 | } |
| 113 | |
| 114 | // Message contains oneof field. |
| 115 | message Oneofs { |
| 116 | oneof union { |
| 117 | string str = 1; |
| 118 | Nested msg = 2; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // Message contains map fields. |
| 123 | message Maps { |
| 124 | map<int32, string> int32_to_str = 1; |
| 125 | map<sfixed64, bool> sfixed64_to_bool = 2; |
| 126 | map<bool, uint32> bool_to_uint32 = 3; |
| 127 | map<uint64, Enum> uint64_to_enum = 4; |
| 128 | map<string, Nested> str_to_nested = 5; |
| 129 | map<string, Oneofs> str_to_oneofs = 6; |
| 130 | } |
| 131 | |
| 132 | // Message contains well-known type fields. |
| 133 | message KnownTypes { |
| 134 | optional google.protobuf.BoolValue opt_bool = 1; |
| 135 | optional google.protobuf.Int32Value opt_int32 = 2; |
| 136 | optional google.protobuf.Int64Value opt_int64 = 3; |
| 137 | optional google.protobuf.UInt32Value opt_uint32 = 4; |
| 138 | optional google.protobuf.UInt64Value opt_uint64 = 5; |
| 139 | optional google.protobuf.FloatValue opt_float = 6; |
| 140 | optional google.protobuf.DoubleValue opt_double = 7; |
| 141 | optional google.protobuf.StringValue opt_string = 8; |
| 142 | optional google.protobuf.BytesValue opt_bytes = 9; |
| 143 | |
| 144 | optional google.protobuf.Duration opt_duration = 20; |
| 145 | optional google.protobuf.Timestamp opt_timestamp = 21; |
| 146 | optional google.protobuf.Struct opt_struct = 25; |
| 147 | optional google.protobuf.ListValue opt_list = 26; |
| 148 | optional google.protobuf.Value opt_value = 27; |
| 149 | optional google.protobuf.Empty opt_empty = 30; |
| 150 | optional google.protobuf.Any opt_any = 32; |
| 151 | } |