github.com/cloudwego/kitex@v0.9.0/pkg/generic/descriptor/type.go (about) 1 /* 2 * Copyright 2021 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 descriptor 18 19 import "github.com/apache/thrift/lib/go/thrift" 20 21 // Type constants in the Thrift protocol 22 type Type byte 23 24 // Types 25 const ( 26 STOP Type = 0 27 VOID Type = 1 28 BOOL Type = 2 29 BYTE Type = 3 30 I08 Type = 3 31 DOUBLE Type = 4 32 I16 Type = 6 33 I32 Type = 8 34 I64 Type = 10 35 STRING Type = 11 36 UTF7 Type = 11 37 STRUCT Type = 12 38 MAP Type = 13 39 SET Type = 14 40 LIST Type = 15 41 UTF8 Type = 16 42 UTF16 Type = 17 43 // BINARY Type = 18 wrong and unusued 44 JSON Type = 19 45 ) 46 47 var typeNames = map[Type]string{ 48 STOP: "STOP", 49 VOID: "VOID", 50 BOOL: "BOOL", 51 BYTE: "BYTE", 52 DOUBLE: "DOUBLE", 53 I16: "I16", 54 I32: "I32", 55 I64: "I64", 56 STRING: "STRING", 57 STRUCT: "STRUCT", 58 MAP: "MAP", 59 SET: "SET", 60 LIST: "LIST", 61 UTF8: "UTF8", 62 UTF16: "UTF16", 63 } 64 65 // String for format and print 66 func (p Type) String() string { 67 if s, ok := typeNames[p]; ok { 68 return s 69 } 70 return "Unknown" 71 } 72 73 // ToThriftTType convert to thrift.TType 74 func (p Type) ToThriftTType() thrift.TType { 75 return thrift.TType(p) 76 } 77 78 // FromThriftTType ... 79 func FromThriftTType(t thrift.TType) Type { 80 return Type(t) 81 } 82 83 // Void use empty struct as void instead of `nil`, because sometimes `nil` was used as optional none 84 type Void struct{}