github.com/cloudwego/dynamicgo@v0.2.6-0.20240519101509-707f41b6b834/meta/const.go (about)

     1  /**
     2   * Copyright 2023 CloudWeGo Authors.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package meta
    18  
    19  import "strconv"
    20  
    21  // Encoding protocol enum
    22  type Encoding int
    23  
    24  const (
    25  	// EncodingJSON is json protocol
    26  	EncodingJSON Encoding = iota + 1
    27  	// EncodingThriftBinary is thrift binary protocol
    28  	EncodingThriftBinary
    29  	// EncodingThriftCompact is thrift compact protocol
    30  	EncodingThriftCompact
    31  	// EncodingProtobuf is protobuf protocol
    32  	EncodingProtobuf
    33  
    34  	// text encoding, see thrift/binary.go::EncodeText()
    35  	EncodingText
    36  )
    37  
    38  // String returns the string representation of Encoding
    39  func (p Encoding) String() string {
    40  	switch p {
    41  	case EncodingJSON:
    42  		return "JSON"
    43  	case EncodingThriftCompact:
    44  		return "ThriftCompact"
    45  	case EncodingThriftBinary:
    46  		return "ThriftBinary"
    47  	case EncodingProtobuf:
    48  		return "Protobuf"
    49  	case EncodingText:
    50  		return "Text"
    51  	default:
    52  		return "Unknown"
    53  	}
    54  }
    55  
    56  // Category is the category of dynamicgo modules
    57  type Category uint8
    58  
    59  const (
    60  	// dynamicgo/json
    61  	JSON Category = 0x01
    62  	// dynamicgo/thrift
    63  	THRIFT Category = 0x02
    64  	// dynamicgo/conv/j2t
    65  	JSON2THRIFT Category = 0x11
    66  	// dynamicgo/conv/t2j
    67  	THRIFT2JSON Category = 0x12
    68  	// dynamicgo/proto
    69  	PROTOBUF Category = 0x03
    70  	// dynamicgo/conv/j2p
    71  	JSON2PROTOBUF Category = 0x13
    72  	// dynamicgo/conv/p2j
    73  	PROTOBUF2JSON Category = 0x14
    74  )
    75  
    76  // String returns the string representation of Category
    77  func (ec Category) String() string {
    78  	switch ec {
    79  	case JSON:
    80  		return "JSON"
    81  	case JSON2THRIFT:
    82  		return "JSON-TO-THRIFT"
    83  	case THRIFT2JSON:
    84  		return "THRIFT-TO-JSON"
    85  	case THRIFT:
    86  		return "THRIFT"
    87  	case PROTOBUF:
    88  		return "PROTOBUF"
    89  	case JSON2PROTOBUF:
    90  		return "JSON-TO-PROTOBUF"
    91  	case PROTOBUF2JSON:
    92  		return "PROTOBUF-TO-JSON"
    93  	default:
    94  		return "CATEGORY " + strconv.Itoa(int(ec))
    95  	}
    96  }
    97  
    98  // NameCase is the case of field name
    99  type NameCase uint8
   100  
   101  const (
   102  	// CaseDefault means use the original field name
   103  	CaseDefault NameCase = iota
   104  	// CaseSnake means use snake case
   105  	CaseSnake
   106  	// CaseUpperCamel means use upper camel case
   107  	CaseUpperCamel
   108  	// CaseLowerCamel means use lower camel case
   109  	CaseLowerCamel
   110  )
   111  
   112  // MapFieldWay is the way to map an given key to field for struct descriptor
   113  type MapFieldWay uint8
   114  
   115  const (
   116  	// MapFieldUseAlias means use alias to map key to field
   117  	MapFieldUseAlias MapFieldWay = iota
   118  	// MapFieldUseFieldName means use field name to map key to field
   119  	MapFieldUseFieldName
   120  	// MapFieldUseBoth means use both alias and field name to map key to field
   121  	MapFieldUseBoth
   122  )
   123  
   124  // ParseFunctionMode indicates to parse only response or request for a IDL
   125  type ParseFunctionMode int8
   126  
   127  const (
   128  	// ParseBoth indicates to parse both request and response for a IDL
   129  	ParseBoth ParseFunctionMode = iota
   130  	// ParseRequestOnly indicates to parse only request for a IDL
   131  	ParseRequestOnly
   132  	// ParseResponseOnly indicates to parse only response for a IDL
   133  	ParseResponseOnly
   134  )
   135  
   136  // ParseServiceMode .
   137  type ParseServiceMode int8
   138  
   139  const (
   140  	// LastServiceOnly forces the parser to parse only the last service definition.
   141  	LastServiceOnly ParseServiceMode = iota
   142  
   143  	// FirstServiceOnly forces the parser to parse only the first service definition.
   144  	FirstServiceOnly
   145  
   146  	// CombineServices forces the parser to combine methods of all service definitions.
   147  	// Note that method names of the service definitions can not be duplicate.
   148  	CombineServices
   149  )