github.com/cloudwego/dynamicgo@v0.2.6-0.20240519101509-707f41b6b834/testdata/idl/example.proto (about)

     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;
     9  option go_package = "pb/example";
    10  
    11  // Scalars contains scalar field types.
    12  message Scalars {
    13    bool s_bool = 1;
    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  
    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  
    29    float s_float = 20;
    30    double s_double = 21;
    31  
    32    bytes s_bytes = 14;
    33    string s_string = 13;
    34  }
    35  
    36  // Message contains repeated fields.
    37  message Repeats {
    38    repeated bool rpt_bool = 1;
    39    repeated int32 rpt_int32 = 2;
    40    repeated int64 rpt_int64 = 3;
    41    repeated uint32 rpt_uint32 = 4;
    42    repeated uint64 rpt_uint64 = 5;
    43    repeated float rpt_float = 6;
    44    repeated double rpt_double = 7;
    45    repeated string rpt_string = 8;
    46    repeated bytes rpt_bytes = 9;
    47  }
    48  
    49  message Proto3Optional {
    50    optional bool opt_bool = 1;
    51    optional int32 opt_int32 = 2;
    52    optional int64 opt_int64 = 3;
    53    optional uint32 opt_uint32 = 4;
    54    optional uint64 opt_uint64 = 5;
    55    optional float opt_float = 6;
    56    optional double opt_double = 7;
    57    optional string opt_string = 8;
    58    optional bytes opt_bytes = 9;
    59    optional Enum opt_enum = 10;
    60    optional Nested opt_message = 11;
    61  }
    62  
    63  enum Enum {
    64    ZERO = 0;
    65    ONE = 1;
    66    TWO = 2;
    67    TEN = 10;
    68  }
    69  
    70  // Message contains enum fields.
    71  message Enums {
    72    Enum s_enum = 1;
    73  
    74    enum NestedEnum {
    75    	CERO = 0;
    76  	UNO = 1;
    77  	DOS = 2;
    78  	DIEZ = 10;
    79    }
    80    NestedEnum s_nested_enum = 3;
    81  }
    82  
    83  // Message contains nested message field.
    84  message Nests {
    85    Nested s_nested = 2;
    86  }
    87  
    88  // Message type used as submessage.
    89  message Nested {
    90    string s_string = 1;
    91    InnerBase Base = 2;
    92  }
    93  
    94  // Message contains oneof field.
    95  message Oneofs {
    96    oneof union {
    97      Enum oneof_enum = 1;
    98      string oneof_string = 2;
    99      Nested oneof_nested = 3;
   100    }
   101  }
   102  
   103  // Message contains map fields.
   104  message Maps {
   105    map<int32, string> int32_to_str = 1;
   106    map<bool, uint32> bool_to_uint32 = 2;
   107    map<uint64, Enum> uint64_to_enum = 3;
   108    map<string, Nested> str_to_nested = 4;
   109    map<string, Oneofs> str_to_oneofs = 5;
   110  }
   111  
   112  // Message for testing json_name option.
   113  message JSONNames {
   114    string s_string = 1 [json_name = "foo_bar"];
   115  }
   116  
   117  message InnerBase {
   118    bool s_bool = 1;
   119    int32 s_int32 = 2;
   120    int64 s_int64 = 3;
   121    uint32 s_uint32 = 4;
   122    uint64 s_uint64 = 5;
   123    sint32 s_sint32 = 6;
   124    sint64 s_sint64 = 7;
   125    fixed32 s_fixed32 = 8;
   126    fixed64 s_fixed64 = 9;
   127    sfixed32 s_sfixed32 = 10;
   128    sfixed64 s_sfixed64 = 11;
   129  
   130    float s_float = 20;
   131    double s_double = 21;
   132  
   133    bytes s_bytes = 14;
   134    string s_string = 13;
   135  }
   136  
   137  message ExampleScalarsReq {
   138    optional string Msg = 1;
   139    optional double Cookie = 2;
   140    string Path = 3;
   141    repeated string Query = 4;
   142    bool Header = 5;
   143    int64 Code = 6;
   144    InnerBase InnerBase = 7;
   145    string RawUri = 8;
   146    double Subfix = 9;
   147    Scalars scalars = 10;
   148  }
   149  
   150  message ExampleScalarsResp {
   151    string Msg = 1;
   152    optional double Cookie = 2;
   153    int32 Status = 3;
   154    optional bool Header = 4;
   155    int64 Code = 5;
   156    double Subfix = 6;
   157    Scalars scalars = 7;
   158  }
   159  
   160  message ExampleMessageReq {
   161    InnerBase Base = 1;
   162  }
   163  
   164  message ExampleMessageResp {
   165    InnerBase Base = 1;
   166  }
   167  
   168  message ExampleNestedReq {
   169    Nested TestNested = 1;
   170  }
   171  
   172  message ExampleNestedResp {
   173    Nested TestNested = 1;
   174  }
   175  
   176  message ExampleParitalReq {
   177    string Msg = 1;
   178    optional double Cookie = 2;
   179    int32 Status = 3;
   180    bool Header = 4;
   181    int64 Code = 5;
   182  }
   183  
   184  message ExamplePartialResp {
   185    string ShortEnglishMsg = 1;
   186    string ChineseMsg = 2;
   187    string LongEnglishMsg = 3;
   188  }
   189  
   190  message ExampleListReq {
   191    Repeats TestList = 1;
   192  }
   193  
   194  message ExampleListResp {
   195    Repeats TestList = 1;
   196  }
   197  
   198  message ExampleMapReq {
   199    Maps TestMap = 1;
   200  }
   201  
   202  message ExampleMapResp {
   203    Maps TestMap = 1;
   204  }
   205  
   206  message ExampleOneofReq {
   207    Oneofs TestOneof = 1;
   208  }
   209  
   210  message ExampleOneofResp {
   211    Oneofs TestOneof = 1;
   212  }
   213  
   214  // Test that RPC services work.
   215  service TestService {
   216    rpc ScalarsMethodTest(ExampleScalarsReq) returns (ExampleScalarsResp);
   217    rpc MessageMethodTest(ExampleMessageReq) returns (ExampleMessageResp);
   218    rpc NestedMethodTest(ExampleNestedReq) returns (ExampleNestedResp);
   219    rpc PartialMethodTest(ExampleParitalReq) returns (ExamplePartialResp);
   220    rpc ListMethodTest(ExampleListReq) returns (ExampleListResp);
   221    rpc MapMethodTest(ExampleMapReq) returns (ExampleMapResp);
   222    rpc OneofMethodTest(ExampleOneofReq) returns (ExampleOneofResp);
   223  }