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 proto3 syntax. |
| 6 | syntax = "proto3"; |
| 7 | |
| 8 | package pb3; |
Joe Tsai | 94e730b | 2020-01-10 23:31:25 -0800 | [diff] [blame] | 9 | option go_package = "google.golang.org/protobuf/internal/testprotos/textpb3"; |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 10 | |
| 11 | // Scalars contains scalar field types. |
| 12 | message Scalars { |
| 13 | bool s_bool = 1; |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 14 | int32 s_int32 = 2; |
| 15 | int64 s_int64 = 3; |
| 16 | uint32 s_uint32 = 4; |
| 17 | uint64 s_uint64 = 5; |
| 18 | sint32 s_sint32 = 6; |
| 19 | sint64 s_sint64 = 7; |
| 20 | fixed32 s_fixed32 = 8; |
| 21 | fixed64 s_fixed64 = 9; |
| 22 | sfixed32 s_sfixed32 = 10; |
| 23 | sfixed64 s_sfixed64 = 11; |
| 24 | |
Herbie Ong | 800c990 | 2018-12-06 15:28:53 -0800 | [diff] [blame] | 25 | // Textproto marshal outputs fields in the same order as this proto |
| 26 | // definition regardless of field number. Following fields are intended to |
| 27 | // test that assumption. |
| 28 | |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 29 | float s_float = 20; |
| 30 | double s_double = 21; |
| 31 | |
| 32 | bytes s_bytes = 14; |
| 33 | string s_string = 13; |
| 34 | } |
| 35 | |
| 36 | enum Enum { |
| 37 | ZERO = 0; |
| 38 | ONE = 1; |
| 39 | TWO = 2; |
| 40 | TEN = 10; |
| 41 | } |
| 42 | |
| 43 | // Message contains enum fields. |
| 44 | message Enums { |
| 45 | Enum s_enum = 1; |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 46 | |
| 47 | enum NestedEnum { |
| 48 | CERO = 0; |
| 49 | UNO = 1; |
| 50 | DOS = 2; |
| 51 | DIEZ = 10; |
| 52 | } |
| 53 | NestedEnum s_nested_enum = 3; |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 54 | } |
| 55 | |
Herbie Ong | 800c990 | 2018-12-06 15:28:53 -0800 | [diff] [blame] | 56 | // Message contains nested message field. |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 57 | message Nests { |
Herbie Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame] | 58 | Nested s_nested = 2; |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | // Message type used as submessage. |
| 62 | message Nested { |
| 63 | string s_string = 1; |
| 64 | Nested s_nested = 2; |
| 65 | } |
Herbie Ong | 8170d69 | 2019-02-13 14:13:21 -0800 | [diff] [blame] | 66 | |
| 67 | // Message contains oneof field. |
| 68 | message Oneofs { |
| 69 | oneof union { |
| 70 | Enum oneof_enum = 1; |
| 71 | string oneof_string = 2; |
| 72 | Nested oneof_nested = 3; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // Message contains map fields. |
| 77 | message Maps { |
| 78 | map<int32, string> int32_to_str = 1; |
| 79 | map<bool, uint32> bool_to_uint32 = 2; |
| 80 | map<uint64, Enum> uint64_to_enum = 3; |
| 81 | map<string, Nested> str_to_nested = 4; |
| 82 | map<string, Oneofs> str_to_oneofs = 5; |
| 83 | } |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 84 | |
| 85 | // Message for testing json_name option. |
| 86 | message JSONNames { |
| 87 | string s_string = 1 [json_name = "foo_bar"]; |
| 88 | } |