github.com/cloudwego/dynamicgo@v0.2.6-0.20240519101509-707f41b6b834/thrift/README.md (about) 1 <!-- Code generated by gomarkdoc. DO NOT EDIT --> 2 3 # thrift 4 5 ```go 6 import "github.com/cloudwego/dynamicgo/thrift" 7 ``` 8 9 ## Index 10 11 - [Constants](<#constants>) 12 - [Variables](<#variables>) 13 - [func FreeBinaryProtocolBuffer(bp *BinaryProtocol)](<#func-freebinaryprotocolbuffer>) 14 - [func FreeRequiresBitmap(b *RequiresBitmap)](<#func-freerequiresbitmap>) 15 - [func GetBinaryMessageHeaderAndFooter(methodName string, msgTyp TMessageType, structID FieldID, seqID int32) (header []byte, footer []byte, err error)](<#func-getbinarymessageheaderandfooter>) 16 - [func RegisterAnnotation(an Annotation, keys ...string)](<#func-registerannotation>) 17 - [func RegisterAnnotationMapper(scope AnnoScope, mapper AnnotationMapper, keys ...string)](<#func-registerannotationmapper>) 18 - [func TypeSize(t Type) int](<#func-typesize>) 19 - [func UnwrapBinaryMessage(proto meta.Encoding, buf []byte) (name string, callType TMessageType, seqID int32, structID FieldID, body []byte, err error)](<#func-unwrapbinarymessage>) 20 - [func WrapBinaryBody(body []byte, methodName string, msgTyp TMessageType, structID FieldID, seqID int32) ([]byte, error)](<#func-wrapbinarybody>) 21 - [type AnnoID](<#type-annoid>) 22 - [func MakeAnnoID(kind AnnoKind, scope AnnoScope, typ AnnoType) AnnoID](<#func-makeannoid>) 23 - [func (t AnnoID) Kind() AnnoKind](<#func-annoid-kind>) 24 - [func (t AnnoID) Scope() AnnoScope](<#func-annoid-scope>) 25 - [func (t AnnoID) Type() AnnoType](<#func-annoid-type>) 26 - [type AnnoKind](<#type-annokind>) 27 - [type AnnoScope](<#type-annoscope>) 28 - [type AnnoType](<#type-annotype>) 29 - [type Annotation](<#type-annotation>) 30 - [func FindAnnotation(key string, scope AnnoScope) Annotation](<#func-findannotation>) 31 - [type AnnotationMapper](<#type-annotationmapper>) 32 - [func FindAnnotationMapper(key string, scope AnnoScope) AnnotationMapper](<#func-findannotationmapper>) 33 - [type BinaryEncoding](<#type-binaryencoding>) 34 - [func (BinaryEncoding) DecodeBool(b []byte) bool](<#func-binaryencoding-decodebool>) 35 - [func (BinaryEncoding) DecodeByte(b []byte) byte](<#func-binaryencoding-decodebyte>) 36 - [func (d BinaryEncoding) DecodeBytes(b []byte) (value []byte)](<#func-binaryencoding-decodebytes>) 37 - [func (BinaryEncoding) DecodeDouble(b []byte) float64](<#func-binaryencoding-decodedouble>) 38 - [func (BinaryEncoding) DecodeInt16(b []byte) int16](<#func-binaryencoding-decodeint16>) 39 - [func (BinaryEncoding) DecodeInt32(b []byte) int32](<#func-binaryencoding-decodeint32>) 40 - [func (BinaryEncoding) DecodeInt64(b []byte) int64](<#func-binaryencoding-decodeint64>) 41 - [func (d BinaryEncoding) DecodeString(b []byte) (value string)](<#func-binaryencoding-decodestring>) 42 - [func (BinaryEncoding) EncodeBinary(b []byte, v []byte)](<#func-binaryencoding-encodebinary>) 43 - [func (BinaryEncoding) EncodeBool(b []byte, v bool)](<#func-binaryencoding-encodebool>) 44 - [func (BinaryEncoding) EncodeByte(b []byte, v byte)](<#func-binaryencoding-encodebyte>) 45 - [func (BinaryEncoding) EncodeDouble(b []byte, v float64)](<#func-binaryencoding-encodedouble>) 46 - [func (BinaryEncoding) EncodeFieldBegin(b []byte, t Type, id FieldID)](<#func-binaryencoding-encodefieldbegin>) 47 - [func (BinaryEncoding) EncodeInt16(b []byte, v int16)](<#func-binaryencoding-encodeint16>) 48 - [func (BinaryEncoding) EncodeInt32(b []byte, v int32)](<#func-binaryencoding-encodeint32>) 49 - [func (BinaryEncoding) EncodeInt64(b []byte, v int64)](<#func-binaryencoding-encodeint64>) 50 - [func (BinaryEncoding) EncodeString(b []byte, v string)](<#func-binaryencoding-encodestring>) 51 - [type BinaryProtocol](<#type-binaryprotocol>) 52 - [func NewBinaryProtocol(buf []byte) *BinaryProtocol](<#func-newbinaryprotocol>) 53 - [func NewBinaryProtocolBuffer() *BinaryProtocol](<#func-newbinaryprotocolbuffer>) 54 - [func (p *BinaryProtocol) DecodeText(val string, desc *TypeDescriptor, disallowUnknown bool, base64Binary bool, useFieldName bool, asJson bool) error](<#func-binaryprotocol-decodetext>) 55 - [func (p *BinaryProtocol) EncodeText(desc *TypeDescriptor, buf *[]byte, byteAsUint8 bool, disallowUnknown bool, base64Binary bool, useFieldName bool, asJson bool) error](<#func-binaryprotocol-encodetext>) 56 - [func (p BinaryProtocol) Left() int](<#func-binaryprotocol-left>) 57 - [func (p *BinaryProtocol) ModifyI32(pos int, value int32) error](<#func-binaryprotocol-modifyi32>) 58 - [func (p BinaryProtocol) RawBuf() []byte](<#func-binaryprotocol-rawbuf>) 59 - [func (p *BinaryProtocol) ReadAnyWithDesc(desc *TypeDescriptor, copyString bool, disallowUnknonw bool, useFieldName bool) (interface{}, error)](<#func-binaryprotocol-readanywithdesc>) 60 - [func (p *BinaryProtocol) ReadBinary(copyBytes bool) (value []byte, err error)](<#func-binaryprotocol-readbinary>) 61 - [func (p *BinaryProtocol) ReadBool() (bool, error)](<#func-binaryprotocol-readbool>) 62 - [func (p *BinaryProtocol) ReadByte() (value byte, err error)](<#func-binaryprotocol-readbyte>) 63 - [func (p *BinaryProtocol) ReadDouble() (value float64, err error)](<#func-binaryprotocol-readdouble>) 64 - [func (p *BinaryProtocol) ReadFieldBegin() (name string, typeID Type, id FieldID, err error)](<#func-binaryprotocol-readfieldbegin>) 65 - [func (p *BinaryProtocol) ReadFieldEnd() error](<#func-binaryprotocol-readfieldend>) 66 - [func (p *BinaryProtocol) ReadI16() (value int16, err error)](<#func-binaryprotocol-readi16>) 67 - [func (p *BinaryProtocol) ReadI32() (value int32, err error)](<#func-binaryprotocol-readi32>) 68 - [func (p *BinaryProtocol) ReadI64() (value int64, err error)](<#func-binaryprotocol-readi64>) 69 - [func (p *BinaryProtocol) ReadInt(t Type) (value int, err error)](<#func-binaryprotocol-readint>) 70 - [func (p *BinaryProtocol) ReadListBegin() (elemType Type, size int, err error)](<#func-binaryprotocol-readlistbegin>) 71 - [func (p *BinaryProtocol) ReadListEnd() error](<#func-binaryprotocol-readlistend>) 72 - [func (p *BinaryProtocol) ReadMapBegin() (kType, vType Type, size int, err error)](<#func-binaryprotocol-readmapbegin>) 73 - [func (p *BinaryProtocol) ReadMapEnd() error](<#func-binaryprotocol-readmapend>) 74 - [func (p *BinaryProtocol) ReadMessageBegin(copyString bool) (name string, typeID TMessageType, seqID int32, err error)](<#func-binaryprotocol-readmessagebegin>) 75 - [func (p *BinaryProtocol) ReadMessageEnd() error](<#func-binaryprotocol-readmessageend>) 76 - [func (p *BinaryProtocol) ReadSetBegin() (elemType Type, size int, err error)](<#func-binaryprotocol-readsetbegin>) 77 - [func (p *BinaryProtocol) ReadSetEnd() error](<#func-binaryprotocol-readsetend>) 78 - [func (p *BinaryProtocol) ReadString(copy bool) (value string, err error)](<#func-binaryprotocol-readstring>) 79 - [func (p *BinaryProtocol) ReadStringWithDesc(desc *TypeDescriptor, buf *[]byte, byteAsUint8 bool, disallowUnknown bool, base64Binary bool) error](<#func-binaryprotocol-readstringwithdesc>) 80 - [func (p *BinaryProtocol) ReadStructBegin() (name string, err error)](<#func-binaryprotocol-readstructbegin>) 81 - [func (p *BinaryProtocol) ReadStructEnd() error](<#func-binaryprotocol-readstructend>) 82 - [func (p *BinaryProtocol) Recycle()](<#func-binaryprotocol-recycle>) 83 - [func (p *BinaryProtocol) Reset()](<#func-binaryprotocol-reset>) 84 - [func (p *BinaryProtocol) Skip(fieldType Type, useNative bool) (err error)](<#func-binaryprotocol-skip>) 85 - [func (p *BinaryProtocol) SkipGo(fieldType Type, maxDepth int) (err error)](<#func-binaryprotocol-skipgo>) 86 - [func (p *BinaryProtocol) SkipNative(fieldType Type, maxDepth int) (err error)](<#func-binaryprotocol-skipnative>) 87 - [func (p BinaryProtocol) UnwrapBody() (string, TMessageType, int32, FieldID, []byte, error)](<#func-binaryprotocol-unwrapbody>) 88 - [func (p *BinaryProtocol) WriteAnyWithDesc(desc *TypeDescriptor, val interface{}, cast bool, disallowUnknown bool, useFieldName bool) error](<#func-binaryprotocol-writeanywithdesc>) 89 - [func (p *BinaryProtocol) WriteBinary(value []byte) error](<#func-binaryprotocol-writebinary>) 90 - [func (p *BinaryProtocol) WriteBool(value bool) error](<#func-binaryprotocol-writebool>) 91 - [func (p *BinaryProtocol) WriteByte(value byte) error](<#func-binaryprotocol-writebyte>) 92 - [func (p *BinaryProtocol) WriteDefaultOrEmpty(field *FieldDescriptor) error](<#func-binaryprotocol-writedefaultorempty>) 93 - [func (p *BinaryProtocol) WriteDouble(value float64) error](<#func-binaryprotocol-writedouble>) 94 - [func (p *BinaryProtocol) WriteEmpty(desc *TypeDescriptor) error](<#func-binaryprotocol-writeempty>) 95 - [func (p *BinaryProtocol) WriteFieldBegin(name string, typeID Type, id FieldID) error](<#func-binaryprotocol-writefieldbegin>) 96 - [func (p *BinaryProtocol) WriteFieldEnd() error](<#func-binaryprotocol-writefieldend>) 97 - [func (p *BinaryProtocol) WriteFieldStop() error](<#func-binaryprotocol-writefieldstop>) 98 - [func (p *BinaryProtocol) WriteI16(value int16) error](<#func-binaryprotocol-writei16>) 99 - [func (p *BinaryProtocol) WriteI32(value int32) error](<#func-binaryprotocol-writei32>) 100 - [func (p *BinaryProtocol) WriteI64(value int64) error](<#func-binaryprotocol-writei64>) 101 - [func (p *BinaryProtocol) WriteInt(t Type, value int) error](<#func-binaryprotocol-writeint>) 102 - [func (p *BinaryProtocol) WriteListBegin(elemType Type, size int) error](<#func-binaryprotocol-writelistbegin>) 103 - [func (p *BinaryProtocol) WriteListBeginWithSizePos(elemType Type, size int) (int, error)](<#func-binaryprotocol-writelistbeginwithsizepos>) 104 - [func (p *BinaryProtocol) WriteListEnd() error](<#func-binaryprotocol-writelistend>) 105 - [func (p *BinaryProtocol) WriteMapBegin(keyType, valueType Type, size int) error](<#func-binaryprotocol-writemapbegin>) 106 - [func (p *BinaryProtocol) WriteMapBeginWithSizePos(keyType, valueType Type, size int) (int, error)](<#func-binaryprotocol-writemapbeginwithsizepos>) 107 - [func (p *BinaryProtocol) WriteMapEnd() error](<#func-binaryprotocol-writemapend>) 108 - [func (p *BinaryProtocol) WriteMessageBegin(name string, typeID TMessageType, seqID int32) error](<#func-binaryprotocol-writemessagebegin>) 109 - [func (p *BinaryProtocol) WriteMessageEnd() error](<#func-binaryprotocol-writemessageend>) 110 - [func (p *BinaryProtocol) WriteSetBegin(elemType Type, size int) error](<#func-binaryprotocol-writesetbegin>) 111 - [func (p *BinaryProtocol) WriteSetEnd() error](<#func-binaryprotocol-writesetend>) 112 - [func (p *BinaryProtocol) WriteString(value string) error](<#func-binaryprotocol-writestring>) 113 - [func (p *BinaryProtocol) WriteStringWithDesc(val string, desc *TypeDescriptor, disallowUnknown bool, base64Binary bool) error](<#func-binaryprotocol-writestringwithdesc>) 114 - [func (p *BinaryProtocol) WriteStructBegin(name string) error](<#func-binaryprotocol-writestructbegin>) 115 - [func (p *BinaryProtocol) WriteStructEnd() error](<#func-binaryprotocol-writestructend>) 116 - [type DefaultValue](<#type-defaultvalue>) 117 - [func (d DefaultValue) GoValue() interface{}](<#func-defaultvalue-govalue>) 118 - [func (d DefaultValue) JSONValue() string](<#func-defaultvalue-jsonvalue>) 119 - [func (d DefaultValue) ThriftBinary() string](<#func-defaultvalue-thriftbinary>) 120 - [type FieldDescriptor](<#type-fielddescriptor>) 121 - [func (f FieldDescriptor) Alias() string](<#func-fielddescriptor-alias>) 122 - [func (f FieldDescriptor) DefaultValue() *DefaultValue](<#func-fielddescriptor-defaultvalue>) 123 - [func (f FieldDescriptor) HTTPMappings() []HttpMapping](<#func-fielddescriptor-httpmappings>) 124 - [func (f FieldDescriptor) ID() FieldID](<#func-fielddescriptor-id>) 125 - [func (f FieldDescriptor) IsRequestBase() bool](<#func-fielddescriptor-isrequestbase>) 126 - [func (f FieldDescriptor) IsResponseBase() bool](<#func-fielddescriptor-isresponsebase>) 127 - [func (f FieldDescriptor) Name() string](<#func-fielddescriptor-name>) 128 - [func (f FieldDescriptor) Required() Requireness](<#func-fielddescriptor-required>) 129 - [func (f FieldDescriptor) Type() *TypeDescriptor](<#func-fielddescriptor-type>) 130 - [func (f FieldDescriptor) ValueMapping() ValueMapping](<#func-fielddescriptor-valuemapping>) 131 - [func (f FieldDescriptor) ValueMappingType() AnnoType](<#func-fielddescriptor-valuemappingtype>) 132 - [type FieldID](<#type-fieldid>) 133 - [type FieldIDMap](<#type-fieldidmap>) 134 - [func (fd FieldIDMap) All() (ret []*FieldDescriptor)](<#func-fieldidmap-all>) 135 - [func (fd FieldIDMap) Get(id FieldID) *FieldDescriptor](<#func-fieldidmap-get>) 136 - [func (fd *FieldIDMap) Set(id FieldID, f *FieldDescriptor)](<#func-fieldidmap-set>) 137 - [func (fd FieldIDMap) Size() int](<#func-fieldidmap-size>) 138 - [type FieldNameMap](<#type-fieldnamemap>) 139 - [func (ft FieldNameMap) All() []*FieldDescriptor](<#func-fieldnamemap-all>) 140 - [func (ft *FieldNameMap) Build()](<#func-fieldnamemap-build>) 141 - [func (ft FieldNameMap) Get(k string) *FieldDescriptor](<#func-fieldnamemap-get>) 142 - [func (ft *FieldNameMap) Set(key string, field *FieldDescriptor) (exist bool)](<#func-fieldnamemap-set>) 143 - [func (ft FieldNameMap) Size() int](<#func-fieldnamemap-size>) 144 - [type FunctionDescriptor](<#type-functiondescriptor>) 145 - [func GetFnDescFromFile(filePath, fnName string, opts Options) *FunctionDescriptor](<#func-getfndescfromfile>) 146 - [func (f FunctionDescriptor) Annotations() map[string][]string](<#func-functiondescriptor-annotations>) 147 - [func (f FunctionDescriptor) Endpoints() []http.Endpoint](<#func-functiondescriptor-endpoints>) 148 - [func (f FunctionDescriptor) HasRequestBase() bool](<#func-functiondescriptor-hasrequestbase>) 149 - [func (f FunctionDescriptor) Name() string](<#func-functiondescriptor-name>) 150 - [func (f FunctionDescriptor) Oneway() bool](<#func-functiondescriptor-oneway>) 151 - [func (f FunctionDescriptor) Request() *TypeDescriptor](<#func-functiondescriptor-request>) 152 - [func (f FunctionDescriptor) Response() *TypeDescriptor](<#func-functiondescriptor-response>) 153 - [type HttpMapping](<#type-httpmapping>) 154 - [type KeyMapping](<#type-keymapping>) 155 - [type OptionMapping](<#type-optionmapping>) 156 - [type Options](<#type-options>) 157 - [func NewDefaultOptions() Options](<#func-newdefaultoptions>) 158 - [func (opts Options) NewDescriptorFromContentWithMethod(ctx context.Context, path, content string, includes map[string]string, isAbsIncludePath bool, methods ...string) (*ServiceDescriptor, error)](<#func-options-newdescriptorfromcontentwithmethod>) 159 - [func (opts Options) NewDescriptorFromPathWithMethod(ctx context.Context, path string, includeDirs []string, methods ...string) (*ServiceDescriptor, error)](<#func-options-newdescriptorfrompathwithmethod>) 160 - [func (opts Options) NewDescritorFromContent(ctx context.Context, path, content string, includes map[string]string, isAbsIncludePath bool) (*ServiceDescriptor, error)](<#func-options-newdescritorfromcontent>) 161 - [func (opts Options) NewDescritorFromPath(ctx context.Context, path string, includeDirs ...string) (*ServiceDescriptor, error)](<#func-options-newdescritorfrompath>) 162 - [type ParseTarget](<#type-parsetarget>) 163 - [type Requireness](<#type-requireness>) 164 - [type RequiresBitmap](<#type-requiresbitmap>) 165 - [func NewRequiresBitmap() *RequiresBitmap](<#func-newrequiresbitmap>) 166 - [func (b RequiresBitmap) CheckRequires(desc *StructDescriptor, writeDefault bool, handler func(field *FieldDescriptor) error) error](<#func-requiresbitmap-checkrequires>) 167 - [func (b RequiresBitmap) CopyTo(to *RequiresBitmap)](<#func-requiresbitmap-copyto>) 168 - [func (b RequiresBitmap) HandleRequires(desc *StructDescriptor, writeRquired bool, writeDefault bool, writeOptional bool, handler func(field *FieldDescriptor) error) error](<#func-requiresbitmap-handlerequires>) 169 - [func (b RequiresBitmap) IsSet(id FieldID) bool](<#func-requiresbitmap-isset>) 170 - [func (b *RequiresBitmap) Set(id FieldID, val Requireness)](<#func-requiresbitmap-set>) 171 - [type ServiceDescriptor](<#type-servicedescriptor>) 172 - [func NewDescritorFromContent(ctx context.Context, path, content string, includes map[string]string, isAbsIncludePath bool) (*ServiceDescriptor, error)](<#func-newdescritorfromcontent>) 173 - [func NewDescritorFromPath(ctx context.Context, path string, includeDirs ...string) (*ServiceDescriptor, error)](<#func-newdescritorfrompath>) 174 - [func (s ServiceDescriptor) Annotations() map[string][]string](<#func-servicedescriptor-annotations>) 175 - [func (s ServiceDescriptor) Functions() map[string]*FunctionDescriptor](<#func-servicedescriptor-functions>) 176 - [func (s *ServiceDescriptor) LookupFunctionByMethod(method string) (*FunctionDescriptor, error)](<#func-servicedescriptor-lookupfunctionbymethod>) 177 - [func (s ServiceDescriptor) Name() string](<#func-servicedescriptor-name>) 178 - [type StructDescriptor](<#type-structdescriptor>) 179 - [func (s StructDescriptor) FieldById(id FieldID) *FieldDescriptor](<#func-structdescriptor-fieldbyid>) 180 - [func (s StructDescriptor) FieldByKey(k string) (field *FieldDescriptor)](<#func-structdescriptor-fieldbykey>) 181 - [func (s StructDescriptor) Fields() []*FieldDescriptor](<#func-structdescriptor-fields>) 182 - [func (s StructDescriptor) GetRequestBase() *FieldDescriptor](<#func-structdescriptor-getrequestbase>) 183 - [func (s StructDescriptor) GetResponseBase() *FieldDescriptor](<#func-structdescriptor-getresponsebase>) 184 - [func (s StructDescriptor) HttpMappingFields() []*FieldDescriptor](<#func-structdescriptor-httpmappingfields>) 185 - [func (s StructDescriptor) Len() int](<#func-structdescriptor-len>) 186 - [func (s StructDescriptor) Name() string](<#func-structdescriptor-name>) 187 - [func (s StructDescriptor) Requires() RequiresBitmap](<#func-structdescriptor-requires>) 188 - [type TMessageType](<#type-tmessagetype>) 189 - [type Type](<#type-type>) 190 - [func FromThriftTType(t thrift.TType) Type](<#func-fromthriftttype>) 191 - [func (p Type) IsComplex() bool](<#func-type-iscomplex>) 192 - [func (p Type) IsInt() bool](<#func-type-isint>) 193 - [func (p Type) String() string](<#func-type-string>) 194 - [func (p Type) ToThriftTType() thrift.TType](<#func-type-tothriftttype>) 195 - [func (p Type) Valid() bool](<#func-type-valid>) 196 - [type TypeDescriptor](<#type-typedescriptor>) 197 - [func FnRequest(fn *FunctionDescriptor) *TypeDescriptor](<#func-fnrequest>) 198 - [func FnResponse(fn *FunctionDescriptor) *TypeDescriptor](<#func-fnresponse>) 199 - [func (d TypeDescriptor) Elem() *TypeDescriptor](<#func-typedescriptor-elem>) 200 - [func (d TypeDescriptor) IsBinary() bool](<#func-typedescriptor-isbinary>) 201 - [func (d TypeDescriptor) Key() *TypeDescriptor](<#func-typedescriptor-key>) 202 - [func (d TypeDescriptor) Name() string](<#func-typedescriptor-name>) 203 - [func (d TypeDescriptor) Struct() *StructDescriptor](<#func-typedescriptor-struct>) 204 - [func (d TypeDescriptor) Type() Type](<#func-typedescriptor-type>) 205 - [type ValueMapping](<#type-valuemapping>) 206 207 208 ## Constants 209 210 ```go 211 const ( 212 // AnnoKeyDynamicGoDeprecated is used to mark a description as deprecated 213 AnnoKeyDynamicGoDeprecated = "dynamicgo.deprecated" 214 // AnnoKeyDynamicGoApiNone is used to deal with http response field with api.none annotation 215 AnnoKeyDynamicGoApiNone = "api.none" 216 ) 217 ``` 218 219 ```go 220 const ( 221 VERSION_MASK = 0xffff0000 222 VERSION_1 = 0x80010000 223 ) 224 ``` 225 226 ```go 227 const MaxSkipDepth = types.TB_SKIP_STACK_SIZE - 1 228 ``` 229 230 ## Variables 231 232 ```go 233 var ( 234 CtxKeyIsBodyRoot = &ctxIsBodyRoot 235 ) 236 ``` 237 238 ## func FreeBinaryProtocolBuffer 239 240 ```go 241 func FreeBinaryProtocolBuffer(bp *BinaryProtocol) 242 ``` 243 244 FreeBinaryProtocol resets the buffer and puts the binary protocol back to sync.Pool 245 246 ## func FreeRequiresBitmap 247 248 ```go 249 func FreeRequiresBitmap(b *RequiresBitmap) 250 ``` 251 252 FreeRequiresBitmap free the bitmap, but not clear its memory 253 254 ## func GetBinaryMessageHeaderAndFooter 255 256 ```go 257 func GetBinaryMessageHeaderAndFooter(methodName string, msgTyp TMessageType, structID FieldID, seqID int32) (header []byte, footer []byte, err error) 258 ``` 259 260 GetBinaryMessageHeaderAndFooter writes the message parameters into header and footer 261 262 ## func RegisterAnnotation 263 264 ```go 265 func RegisterAnnotation(an Annotation, keys ...string) 266 ``` 267 268 RegisterAnnotation register an annotation on specific AnnoScope 269 270 ## func RegisterAnnotationMapper 271 272 ```go 273 func RegisterAnnotationMapper(scope AnnoScope, mapper AnnotationMapper, keys ...string) 274 ``` 275 276 RegisterAnnotationMapper register a annotation mapper on specific scope 277 278 ## func TypeSize 279 280 ```go 281 func TypeSize(t Type) int 282 ``` 283 284 TypeSize returns the size of the given type. \-1 means variable size \(LIST, SET, MAP, STRING\) 0 means unknown type 285 286 ## func UnwrapBinaryMessage 287 288 ```go 289 func UnwrapBinaryMessage(proto meta.Encoding, buf []byte) (name string, callType TMessageType, seqID int32, structID FieldID, body []byte, err error) 290 ``` 291 292 UnwrapBinaryMessage unwraps the message parameters from the buf 293 294 ## func WrapBinaryBody 295 296 ```go 297 func WrapBinaryBody(body []byte, methodName string, msgTyp TMessageType, structID FieldID, seqID int32) ([]byte, error) 298 ``` 299 300 WrapBinaryMessage wraps the message with header and footer and body 301 302 ## type AnnoID 303 304 AnnoID is the unique id of an annotation, which is composed of kind, scope and type: 305 306 ``` 307 0xff000000: AnnoKind 308 0x00ff0000: AnnoScope 309 0x0000ffff: AnnoType 310 ``` 311 312 ```go 313 type AnnoID uint32 314 ``` 315 316 ### func MakeAnnoID 317 318 ```go 319 func MakeAnnoID(kind AnnoKind, scope AnnoScope, typ AnnoType) AnnoID 320 ``` 321 322 ### func \(AnnoID\) Kind 323 324 ```go 325 func (t AnnoID) Kind() AnnoKind 326 ``` 327 328 Kind returns the kind of the annotation 329 330 ### func \(AnnoID\) Scope 331 332 ```go 333 func (t AnnoID) Scope() AnnoScope 334 ``` 335 336 Scope returns the scope of the annotation 337 338 ### func \(AnnoID\) Type 339 340 ```go 341 func (t AnnoID) Type() AnnoType 342 ``` 343 344 Type returns the type of the annotation 345 346 ## type AnnoKind 347 348 AnnoKind is the kind of annotation, which defines the result handler of Annotation.Make\(\) 349 350 ```go 351 type AnnoKind uint8 352 ``` 353 354 ```go 355 const ( 356 // AnnoKindHttpMappping is the kind of http mapping annotation 357 // These annotations Make() will return HTTPMapping 358 AnnoKindHttpMappping AnnoKind = iota + 1 359 360 // AnnotationKindKeyMapping is the kind of key mapping annotation 361 // These annotations Make() will return KeyMapping 362 AnnoKindValueMapping 363 364 // AnnotationKindValueMapping is the kind of value mapping annotation 365 // These annotations Make() will return ValueMapping 366 AnnoKindOptionMapping 367 368 // AnnotationKindOptionMapping is the kind of option mapping annotation 369 // These annotations Make() will return OptionMapping 370 AnnoKindKeyMapping 371 ) 372 ``` 373 374 ## type AnnoScope 375 376 AnnoScope is effective scope of annotation 377 378 ```go 379 type AnnoScope uint8 380 ``` 381 382 ```go 383 const ( 384 // AnnoScopeService works on service description 385 AnnoScopeService AnnoScope = iota + 1 386 387 // AnnoScopeFunction works on function description 388 AnnoScopeFunction 389 390 // AnnoScopeStruct works on struct description 391 AnnoScopeStruct 392 393 // AnnoScopeField works on field description 394 AnnoScopeField 395 ) 396 ``` 397 398 ## type AnnoType 399 400 AnnoType is the specific type of an annotation 401 402 ```go 403 type AnnoType uint16 404 ``` 405 406 ## type Annotation 407 408 Annotation idl annotation interface 409 410 ```go 411 type Annotation interface { 412 // unique id of the Annotation 413 ID() AnnoID 414 415 // Make makes the handler function under specific values and idl description 416 // 417 // desc is specific type to its registered AnnoScope: 418 // AnnoScopeService: desc is *parser.Service 419 // AnnoScopeFunction: desc is *parser.Function 420 // AnnoScopeStruct: desc is *parser.StructLike 421 // AnnoScopeField: desc is *parser.Field 422 // 423 // returned handler SHOULD BE one interface according to its AnnoKind: 424 // AnnoKindHttpMappping: HTTPMapping interface 425 // AnnoKindKeyMapping: KeyMapping interface 426 // AnnoKindKeyMapping: ValueMapping interface 427 // AnnoKindOptionMapping: OptionMapping interface 428 Make(ctx context.Context, values []parser.Annotation, desc interface{}) (handler interface{}, err error) 429 } 430 ``` 431 432 ### func FindAnnotation 433 434 ```go 435 func FindAnnotation(key string, scope AnnoScope) Annotation 436 ``` 437 438 ## type AnnotationMapper 439 440 AnnotationMapper is used to convert a annotation to equivalent annotations desc is specific to its registered AnnoScope: AnnoScopeService: desc is \*parser.Service AnnoScopeFunction: desc is \*parser.Function AnnoScopeStruct: desc is \*parser.StructLike AnnoScopeField: desc is \*parser.Field 441 442 ```go 443 type AnnotationMapper interface { 444 // Map map a annotation to equivalent annotations 445 Map(ctx context.Context, ann []parser.Annotation, desc interface{}, opt Options) (cur []parser.Annotation, next []parser.Annotation, err error) 446 } 447 ``` 448 449 ### func FindAnnotationMapper 450 451 ```go 452 func FindAnnotationMapper(key string, scope AnnoScope) AnnotationMapper 453 ``` 454 455 ## type BinaryEncoding 456 457 BinaryEncoding is the implementation of Encoding for binary encoding. 458 459 ```go 460 type BinaryEncoding struct{} 461 ``` 462 463 ### func \(BinaryEncoding\) DecodeBool 464 465 ```go 466 func (BinaryEncoding) DecodeBool(b []byte) bool 467 ``` 468 469 EncodeFieldEnd encodes a field end. 470 471 ### func \(BinaryEncoding\) DecodeByte 472 473 ```go 474 func (BinaryEncoding) DecodeByte(b []byte) byte 475 ``` 476 477 DecodeByte decodes a byte value. 478 479 ### func \(BinaryEncoding\) DecodeBytes 480 481 ```go 482 func (d BinaryEncoding) DecodeBytes(b []byte) (value []byte) 483 ``` 484 485 DecodeBinary decodes a binary value. 486 487 ### func \(BinaryEncoding\) DecodeDouble 488 489 ```go 490 func (BinaryEncoding) DecodeDouble(b []byte) float64 491 ``` 492 493 DecodeDouble decodes a double value. 494 495 ### func \(BinaryEncoding\) DecodeInt16 496 497 ```go 498 func (BinaryEncoding) DecodeInt16(b []byte) int16 499 ``` 500 501 DecodeInt16 decodes a int16 value. 502 503 ### func \(BinaryEncoding\) DecodeInt32 504 505 ```go 506 func (BinaryEncoding) DecodeInt32(b []byte) int32 507 ``` 508 509 DecodeInt32 decodes a int32 value. 510 511 ### func \(BinaryEncoding\) DecodeInt64 512 513 ```go 514 func (BinaryEncoding) DecodeInt64(b []byte) int64 515 ``` 516 517 DecodeInt64 decodes a int64 value. 518 519 ### func \(BinaryEncoding\) DecodeString 520 521 ```go 522 func (d BinaryEncoding) DecodeString(b []byte) (value string) 523 ``` 524 525 DecodeString decodes a string value. 526 527 ### func \(BinaryEncoding\) EncodeBinary 528 529 ```go 530 func (BinaryEncoding) EncodeBinary(b []byte, v []byte) 531 ``` 532 533 EncodeBinary encodes a binary value. 534 535 ### func \(BinaryEncoding\) EncodeBool 536 537 ```go 538 func (BinaryEncoding) EncodeBool(b []byte, v bool) 539 ``` 540 541 EncodeBool encodes a bool value. 542 543 ### func \(BinaryEncoding\) EncodeByte 544 545 ```go 546 func (BinaryEncoding) EncodeByte(b []byte, v byte) 547 ``` 548 549 EncodeByte encodes a byte value. 550 551 ### func \(BinaryEncoding\) EncodeDouble 552 553 ```go 554 func (BinaryEncoding) EncodeDouble(b []byte, v float64) 555 ``` 556 557 ### func \(BinaryEncoding\) EncodeFieldBegin 558 559 ```go 560 func (BinaryEncoding) EncodeFieldBegin(b []byte, t Type, id FieldID) 561 ``` 562 563 EncodeFieldBegin encodes a field begin. 564 565 ### func \(BinaryEncoding\) EncodeInt16 566 567 ```go 568 func (BinaryEncoding) EncodeInt16(b []byte, v int16) 569 ``` 570 571 EncodeInt16 encodes a int16 value. 572 573 ### func \(BinaryEncoding\) EncodeInt32 574 575 ```go 576 func (BinaryEncoding) EncodeInt32(b []byte, v int32) 577 ``` 578 579 EncodeInt32 encodes a int32 value. 580 581 ### func \(BinaryEncoding\) EncodeInt64 582 583 ```go 584 func (BinaryEncoding) EncodeInt64(b []byte, v int64) 585 ``` 586 587 EncodeInt64 encodes a int64 value. 588 589 ### func \(BinaryEncoding\) EncodeString 590 591 ```go 592 func (BinaryEncoding) EncodeString(b []byte, v string) 593 ``` 594 595 EncodeString encodes a string value. 596 597 ## type BinaryProtocol 598 599 BinaryProtocol implements the BinaryProtocol see https://github.com/apache/thrift/blob/master/doc/specs/thrift-binary-protocol.md 600 601 ```go 602 type BinaryProtocol struct { 603 Buf []byte 604 Read int 605 } 606 ``` 607 608 ### func NewBinaryProtocol 609 610 ```go 611 func NewBinaryProtocol(buf []byte) *BinaryProtocol 612 ``` 613 614 NewBinaryProtocol get a new binary protocol from sync.Pool. 615 616 ### func NewBinaryProtocolBuffer 617 618 ```go 619 func NewBinaryProtocolBuffer() *BinaryProtocol 620 ``` 621 622 NewBinaryProtocolBuffer gets a new binary protocol from sync.Pool and reuse the buffer in pool 623 624 ### func \(\*BinaryProtocol\) DecodeText 625 626 ```go 627 func (p *BinaryProtocol) DecodeText(val string, desc *TypeDescriptor, disallowUnknown bool, base64Binary bool, useFieldName bool, asJson bool) error 628 ``` 629 630 DecodeText decode special text\-encoded val with desc and write it into buffer The encoding of val should be compatible with \`EncodeText\(\)\` WARNING: this function is not fully implemented, only support json\-encoded string for LIST/MAP/SET/STRUCT 631 632 ### func \(\*BinaryProtocol\) EncodeText 633 634 ```go 635 func (p *BinaryProtocol) EncodeText(desc *TypeDescriptor, buf *[]byte, byteAsUint8 bool, disallowUnknown bool, base64Binary bool, useFieldName bool, asJson bool) error 636 ``` 637 638 EncodeText reads thrift data with descriptor, and converts it to a specail text\-protocol string: This protocol is similar to JSON, excepts its key \(or field id\) IS NOT QUOTED unless it is a string type: \- LIST/SET's all elements will be joined with ',', and if asJson is true the entiry value will be wrapped by '\[' \(start\) and '\]' \(end\). \- MAP's each pair of key and value will be binded with ':', all elements will be joined with ',', and if asJson is true the entiry value will be wrapped by '\{' \(start\) and '\}' \(end\). \- STRUCT's each pair of field \(name or id\) and value will be binded with ':', all elements will be joined with ',', and if asJson is true the entiry value will be wrapped by '\{' \(start\) and '\}' \(end\). \- STRING \(including key\) will be wrapped by '"' if asJson is true. 639 640 ### func \(BinaryProtocol\) Left 641 642 ```go 643 func (p BinaryProtocol) Left() int 644 ``` 645 646 Left returns the left bytes to read 647 648 ### func \(\*BinaryProtocol\) ModifyI32 649 650 ```go 651 func (p *BinaryProtocol) ModifyI32(pos int, value int32) error 652 ``` 653 654 ModifyI16 write int32 into the buffer at the given position 655 656 ### func \(BinaryProtocol\) RawBuf 657 658 ```go 659 func (p BinaryProtocol) RawBuf() []byte 660 ``` 661 662 RawBuf returns the raw buffer of the protocol 663 664 ### func \(\*BinaryProtocol\) ReadAnyWithDesc 665 666 ```go 667 func (p *BinaryProtocol) ReadAnyWithDesc(desc *TypeDescriptor, copyString bool, disallowUnknonw bool, useFieldName bool) (interface{}, error) 668 ``` 669 670 ReadAnyWithDesc explains thrift data with descriptor and converts it to go interface\{\} \- LIST/SET will be converted to \[\]interface\{\} \- MAP will be converted to map\[string\]interface\{\} or map\[int\]interface\{\} or map\[interface\{\}\]interface \(depends on its key type\) \- STRUCT will be converted to map\[FieldID\]interface\{\} 671 672 <details><summary>Example</summary> 673 <p> 674 675 ```go 676 { 677 p1, err := NewDescritorFromPath(context.Background(), "../testdata/idl/example2.thrift") 678 if err != nil { 679 panic(err) 680 } 681 example2ReqDesc := p1.Functions()["ExampleMethod"].Request().Struct().FieldById(1).Type() 682 data, err := ioutil.ReadFile("../testdata/data/example2.bin") 683 if err != nil { 684 panic(err) 685 } 686 687 p := NewBinaryProtocol(data) 688 v, err := p.ReadAnyWithDesc(example2ReqDesc, false, false, true) 689 if err != nil { 690 panic(err) 691 } 692 fmt.Printf("%#v", v) 693 p = NewBinaryProtocolBuffer() 694 err = p.WriteAnyWithDesc(example2ReqDesc, v, true, true, true) 695 if err != nil { 696 panic(err) 697 } 698 fmt.Printf("%x", p.RawBuf()) 699 } 700 ``` 701 702 </p> 703 </details> 704 705 ### func \(\*BinaryProtocol\) ReadBinary 706 707 ```go 708 func (p *BinaryProtocol) ReadBinary(copyBytes bool) (value []byte, err error) 709 ``` 710 711 ReadBinary ... 712 713 ### func \(\*BinaryProtocol\) ReadBool 714 715 ```go 716 func (p *BinaryProtocol) ReadBool() (bool, error) 717 ``` 718 719 ReadBool ... 720 721 ### func \(\*BinaryProtocol\) ReadByte 722 723 ```go 724 func (p *BinaryProtocol) ReadByte() (value byte, err error) 725 ``` 726 727 ReadByte ... 728 729 ### func \(\*BinaryProtocol\) ReadDouble 730 731 ```go 732 func (p *BinaryProtocol) ReadDouble() (value float64, err error) 733 ``` 734 735 ReadDouble ... 736 737 ### func \(\*BinaryProtocol\) ReadFieldBegin 738 739 ```go 740 func (p *BinaryProtocol) ReadFieldBegin() (name string, typeID Type, id FieldID, err error) 741 ``` 742 743 ReadFieldBegin ... 744 745 ### func \(\*BinaryProtocol\) ReadFieldEnd 746 747 ```go 748 func (p *BinaryProtocol) ReadFieldEnd() error 749 ``` 750 751 ReadFieldEnd ... 752 753 ### func \(\*BinaryProtocol\) ReadI16 754 755 ```go 756 func (p *BinaryProtocol) ReadI16() (value int16, err error) 757 ``` 758 759 ReadI16 ... 760 761 ### func \(\*BinaryProtocol\) ReadI32 762 763 ```go 764 func (p *BinaryProtocol) ReadI32() (value int32, err error) 765 ``` 766 767 ReadI32 ... 768 769 ### func \(\*BinaryProtocol\) ReadI64 770 771 ```go 772 func (p *BinaryProtocol) ReadI64() (value int64, err error) 773 ``` 774 775 ReadI64 ... 776 777 ### func \(\*BinaryProtocol\) ReadInt 778 779 ```go 780 func (p *BinaryProtocol) ReadInt(t Type) (value int, err error) 781 ``` 782 783 ReadInt ... 784 785 ### func \(\*BinaryProtocol\) ReadListBegin 786 787 ```go 788 func (p *BinaryProtocol) ReadListBegin() (elemType Type, size int, err error) 789 ``` 790 791 ReadListBegin ... 792 793 ### func \(\*BinaryProtocol\) ReadListEnd 794 795 ```go 796 func (p *BinaryProtocol) ReadListEnd() error 797 ``` 798 799 ReadListEnd ... 800 801 ### func \(\*BinaryProtocol\) ReadMapBegin 802 803 ```go 804 func (p *BinaryProtocol) ReadMapBegin() (kType, vType Type, size int, err error) 805 ``` 806 807 ReadMapBegin ... 808 809 ### func \(\*BinaryProtocol\) ReadMapEnd 810 811 ```go 812 func (p *BinaryProtocol) ReadMapEnd() error 813 ``` 814 815 ReadMapEnd ... 816 817 ### func \(\*BinaryProtocol\) ReadMessageBegin 818 819 ```go 820 func (p *BinaryProtocol) ReadMessageBegin(copyString bool) (name string, typeID TMessageType, seqID int32, err error) 821 ``` 822 823 ReadMessageBegin ... 824 825 ### func \(\*BinaryProtocol\) ReadMessageEnd 826 827 ```go 828 func (p *BinaryProtocol) ReadMessageEnd() error 829 ``` 830 831 ReadMessageEnd ... 832 833 ### func \(\*BinaryProtocol\) ReadSetBegin 834 835 ```go 836 func (p *BinaryProtocol) ReadSetBegin() (elemType Type, size int, err error) 837 ``` 838 839 ReadSetBegin ... 840 841 ### func \(\*BinaryProtocol\) ReadSetEnd 842 843 ```go 844 func (p *BinaryProtocol) ReadSetEnd() error 845 ``` 846 847 ReadSetEnd ... 848 849 ### func \(\*BinaryProtocol\) ReadString 850 851 ```go 852 func (p *BinaryProtocol) ReadString(copy bool) (value string, err error) 853 ``` 854 855 ReadString ... 856 857 ### func \(\*BinaryProtocol\) ReadStringWithDesc 858 859 ```go 860 func (p *BinaryProtocol) ReadStringWithDesc(desc *TypeDescriptor, buf *[]byte, byteAsUint8 bool, disallowUnknown bool, base64Binary bool) error 861 ``` 862 863 ReadStringWithDesc explains thrift data with desc and converts to simple string 864 865 ### func \(\*BinaryProtocol\) ReadStructBegin 866 867 ```go 868 func (p *BinaryProtocol) ReadStructBegin() (name string, err error) 869 ``` 870 871 ReadStructBegin ... 872 873 ### func \(\*BinaryProtocol\) ReadStructEnd 874 875 ```go 876 func (p *BinaryProtocol) ReadStructEnd() error 877 ``` 878 879 ReadStructEnd ... 880 881 ### func \(\*BinaryProtocol\) Recycle 882 883 ```go 884 func (p *BinaryProtocol) Recycle() 885 ``` 886 887 Recycle put the protocol back to sync.Pool 888 889 ### func \(\*BinaryProtocol\) Reset 890 891 ```go 892 func (p *BinaryProtocol) Reset() 893 ``` 894 895 Reset resets the buffer and read position 896 897 ### func \(\*BinaryProtocol\) Skip 898 899 ```go 900 func (p *BinaryProtocol) Skip(fieldType Type, useNative bool) (err error) 901 ``` 902 903 Skip skips over the value for the given type. 904 905 ### func \(\*BinaryProtocol\) SkipGo 906 907 ```go 908 func (p *BinaryProtocol) SkipGo(fieldType Type, maxDepth int) (err error) 909 ``` 910 911 SkipGo skips over the value for the given type using Go implementation. 912 913 ### func \(\*BinaryProtocol\) SkipNative 914 915 ```go 916 func (p *BinaryProtocol) SkipNative(fieldType Type, maxDepth int) (err error) 917 ``` 918 919 Skip skips over teh value for the given type using native C implementation. 920 921 ### func \(BinaryProtocol\) UnwrapBody 922 923 ```go 924 func (p BinaryProtocol) UnwrapBody() (string, TMessageType, int32, FieldID, []byte, error) 925 ``` 926 927 UnwrapBody unwraps the message parameters from its buf 928 929 ### func \(\*BinaryProtocol\) WriteAnyWithDesc 930 931 ```go 932 func (p *BinaryProtocol) WriteAnyWithDesc(desc *TypeDescriptor, val interface{}, cast bool, disallowUnknown bool, useFieldName bool) error 933 ``` 934 935 WriteAnyWithDesc explain desc and val and write them into buffer \- LIST/SET will be converted from \[\]interface\{\} \- MAP will be converted from map\[string\]interface\{\} or map\[int\]interface\{\} \- STRUCT will be converted from map\[FieldID\]interface\{\} 936 937 ### func \(\*BinaryProtocol\) WriteBinary 938 939 ```go 940 func (p *BinaryProtocol) WriteBinary(value []byte) error 941 ``` 942 943 WriteBinary ... 944 945 ### func \(\*BinaryProtocol\) WriteBool 946 947 ```go 948 func (p *BinaryProtocol) WriteBool(value bool) error 949 ``` 950 951 WriteBool ... 952 953 ### func \(\*BinaryProtocol\) WriteByte 954 955 ```go 956 func (p *BinaryProtocol) WriteByte(value byte) error 957 ``` 958 959 WriteByte ... 960 961 ### func \(\*BinaryProtocol\) WriteDefaultOrEmpty 962 963 ```go 964 func (p *BinaryProtocol) WriteDefaultOrEmpty(field *FieldDescriptor) error 965 ``` 966 967 WriteDefaultOrEmpty write default value if any, otherwise write zero value 968 969 ### func \(\*BinaryProtocol\) WriteDouble 970 971 ```go 972 func (p *BinaryProtocol) WriteDouble(value float64) error 973 ``` 974 975 WriteDouble ... 976 977 ### func \(\*BinaryProtocol\) WriteEmpty 978 979 ```go 980 func (p *BinaryProtocol) WriteEmpty(desc *TypeDescriptor) error 981 ``` 982 983 WriteEmpty write zero value 984 985 ### func \(\*BinaryProtocol\) WriteFieldBegin 986 987 ```go 988 func (p *BinaryProtocol) WriteFieldBegin(name string, typeID Type, id FieldID) error 989 ``` 990 991 WriteFieldBegin ... 992 993 ### func \(\*BinaryProtocol\) WriteFieldEnd 994 995 ```go 996 func (p *BinaryProtocol) WriteFieldEnd() error 997 ``` 998 999 WriteFieldEnd ... 1000 1001 ### func \(\*BinaryProtocol\) WriteFieldStop 1002 1003 ```go 1004 func (p *BinaryProtocol) WriteFieldStop() error 1005 ``` 1006 1007 WriteFieldStop ... 1008 1009 ### func \(\*BinaryProtocol\) WriteI16 1010 1011 ```go 1012 func (p *BinaryProtocol) WriteI16(value int16) error 1013 ``` 1014 1015 WriteI16 ... 1016 1017 ### func \(\*BinaryProtocol\) WriteI32 1018 1019 ```go 1020 func (p *BinaryProtocol) WriteI32(value int32) error 1021 ``` 1022 1023 WriteI32 ... 1024 1025 ### func \(\*BinaryProtocol\) WriteI64 1026 1027 ```go 1028 func (p *BinaryProtocol) WriteI64(value int64) error 1029 ``` 1030 1031 WriteI64 ... 1032 1033 ### func \(\*BinaryProtocol\) WriteInt 1034 1035 ```go 1036 func (p *BinaryProtocol) WriteInt(t Type, value int) error 1037 ``` 1038 1039 WriteInt ... 1040 1041 ### func \(\*BinaryProtocol\) WriteListBegin 1042 1043 ```go 1044 func (p *BinaryProtocol) WriteListBegin(elemType Type, size int) error 1045 ``` 1046 1047 WriteListBegin ... 1048 1049 ### func \(\*BinaryProtocol\) WriteListBeginWithSizePos 1050 1051 ```go 1052 func (p *BinaryProtocol) WriteListBeginWithSizePos(elemType Type, size int) (int, error) 1053 ``` 1054 1055 WriteListBeginWithSizePos writes the list begin, and return the buffer position of the size data 1056 1057 ### func \(\*BinaryProtocol\) WriteListEnd 1058 1059 ```go 1060 func (p *BinaryProtocol) WriteListEnd() error 1061 ``` 1062 1063 WriteListEnd ... 1064 1065 ### func \(\*BinaryProtocol\) WriteMapBegin 1066 1067 ```go 1068 func (p *BinaryProtocol) WriteMapBegin(keyType, valueType Type, size int) error 1069 ``` 1070 1071 WriteMapBegin ... 1072 1073 ### func \(\*BinaryProtocol\) WriteMapBeginWithSizePos 1074 1075 ```go 1076 func (p *BinaryProtocol) WriteMapBeginWithSizePos(keyType, valueType Type, size int) (int, error) 1077 ``` 1078 1079 WriteMapBeginWithSizePos writes the map begin, and return the buffer position of the size data 1080 1081 ### func \(\*BinaryProtocol\) WriteMapEnd 1082 1083 ```go 1084 func (p *BinaryProtocol) WriteMapEnd() error 1085 ``` 1086 1087 WriteMapEnd ... 1088 1089 ### func \(\*BinaryProtocol\) WriteMessageBegin 1090 1091 ```go 1092 func (p *BinaryProtocol) WriteMessageBegin(name string, typeID TMessageType, seqID int32) error 1093 ``` 1094 1095 WriteMessageBegin ... 1096 1097 ### func \(\*BinaryProtocol\) WriteMessageEnd 1098 1099 ```go 1100 func (p *BinaryProtocol) WriteMessageEnd() error 1101 ``` 1102 1103 WriteMessageEnd ... 1104 1105 ### func \(\*BinaryProtocol\) WriteSetBegin 1106 1107 ```go 1108 func (p *BinaryProtocol) WriteSetBegin(elemType Type, size int) error 1109 ``` 1110 1111 WriteSetBegin ... 1112 1113 ### func \(\*BinaryProtocol\) WriteSetEnd 1114 1115 ```go 1116 func (p *BinaryProtocol) WriteSetEnd() error 1117 ``` 1118 1119 WriteSetEnd ... 1120 1121 ### func \(\*BinaryProtocol\) WriteString 1122 1123 ```go 1124 func (p *BinaryProtocol) WriteString(value string) error 1125 ``` 1126 1127 WriteString ... 1128 1129 ### func \(\*BinaryProtocol\) WriteStringWithDesc 1130 1131 ```go 1132 func (p *BinaryProtocol) WriteStringWithDesc(val string, desc *TypeDescriptor, disallowUnknown bool, base64Binary bool) error 1133 ``` 1134 1135 WriteStringWithDesc explain simple string val with desc and convert to thrift data 1136 1137 ### func \(\*BinaryProtocol\) WriteStructBegin 1138 1139 ```go 1140 func (p *BinaryProtocol) WriteStructBegin(name string) error 1141 ``` 1142 1143 WriteStructBegin ... 1144 1145 ### func \(\*BinaryProtocol\) WriteStructEnd 1146 1147 ```go 1148 func (p *BinaryProtocol) WriteStructEnd() error 1149 ``` 1150 1151 WriteStructEnd ... 1152 1153 ## type DefaultValue 1154 1155 DefaultValue is the default value of a field 1156 1157 ```go 1158 type DefaultValue struct { 1159 // contains filtered or unexported fields 1160 } 1161 ``` 1162 1163 ### func \(DefaultValue\) GoValue 1164 1165 ```go 1166 func (d DefaultValue) GoValue() interface{} 1167 ``` 1168 1169 GoValue return the go runtime representation of the default value 1170 1171 ### func \(DefaultValue\) JSONValue 1172 1173 ```go 1174 func (d DefaultValue) JSONValue() string 1175 ``` 1176 1177 JSONValue return the json\-encoded representation of the default value 1178 1179 ### func \(DefaultValue\) ThriftBinary 1180 1181 ```go 1182 func (d DefaultValue) ThriftBinary() string 1183 ``` 1184 1185 ThriftBinary return the thrift\-binary\-encoded representation of the default value 1186 1187 ## type FieldDescriptor 1188 1189 FieldDescriptor is the runtime descriptor of a field in a struct 1190 1191 ```go 1192 type FieldDescriptor struct { 1193 // contains filtered or unexported fields 1194 } 1195 ``` 1196 1197 ### func \(FieldDescriptor\) Alias 1198 1199 ```go 1200 func (f FieldDescriptor) Alias() string 1201 ``` 1202 1203 Alias returns the alias of a field 1204 1205 ### func \(FieldDescriptor\) DefaultValue 1206 1207 ```go 1208 func (f FieldDescriptor) DefaultValue() *DefaultValue 1209 ``` 1210 1211 DefaultValue returns the default value of a field 1212 1213 ### func \(FieldDescriptor\) HTTPMappings 1214 1215 ```go 1216 func (f FieldDescriptor) HTTPMappings() []HttpMapping 1217 ``` 1218 1219 HTTPMappings returns the http\-mapping annotations of a field 1220 1221 ### func \(FieldDescriptor\) ID 1222 1223 ```go 1224 func (f FieldDescriptor) ID() FieldID 1225 ``` 1226 1227 ID returns the id of a field 1228 1229 ### func \(FieldDescriptor\) IsRequestBase 1230 1231 ```go 1232 func (f FieldDescriptor) IsRequestBase() bool 1233 ``` 1234 1235 IsRequestBase tells if the field is base.Base 1236 1237 ### func \(FieldDescriptor\) IsResponseBase 1238 1239 ```go 1240 func (f FieldDescriptor) IsResponseBase() bool 1241 ``` 1242 1243 IsResponseBase tells if the field is base.BaseResp 1244 1245 ### func \(FieldDescriptor\) Name 1246 1247 ```go 1248 func (f FieldDescriptor) Name() string 1249 ``` 1250 1251 Name returns the name of a field 1252 1253 ### func \(FieldDescriptor\) Required 1254 1255 ```go 1256 func (f FieldDescriptor) Required() Requireness 1257 ``` 1258 1259 Required return the requiredness of a field 1260 1261 ### func \(FieldDescriptor\) Type 1262 1263 ```go 1264 func (f FieldDescriptor) Type() *TypeDescriptor 1265 ``` 1266 1267 Type returns the type descriptor of a field 1268 1269 ### func \(FieldDescriptor\) ValueMapping 1270 1271 ```go 1272 func (f FieldDescriptor) ValueMapping() ValueMapping 1273 ``` 1274 1275 ValueMapping returns the value\-mapping annotation of a field 1276 1277 ### func \(FieldDescriptor\) ValueMappingType 1278 1279 ```go 1280 func (f FieldDescriptor) ValueMappingType() AnnoType 1281 ``` 1282 1283 ValueMappingType returns the value\-mapping annotation's type of a field 1284 1285 ## type FieldID 1286 1287 FieldID is used to identify a field in a struct 1288 1289 ```go 1290 type FieldID uint16 1291 ``` 1292 1293 ## type FieldIDMap 1294 1295 FieldIDMap is a map from field id to field descriptor 1296 1297 ```go 1298 type FieldIDMap struct { 1299 // contains filtered or unexported fields 1300 } 1301 ``` 1302 1303 ### func \(FieldIDMap\) All 1304 1305 ```go 1306 func (fd FieldIDMap) All() (ret []*FieldDescriptor) 1307 ``` 1308 1309 All returns all field descriptors 1310 1311 ### func \(FieldIDMap\) Get 1312 1313 ```go 1314 func (fd FieldIDMap) Get(id FieldID) *FieldDescriptor 1315 ``` 1316 1317 Get gets the field descriptor for the given id 1318 1319 ### func \(\*FieldIDMap\) Set 1320 1321 ```go 1322 func (fd *FieldIDMap) Set(id FieldID, f *FieldDescriptor) 1323 ``` 1324 1325 Set sets the field descriptor for the given id 1326 1327 ### func \(FieldIDMap\) Size 1328 1329 ```go 1330 func (fd FieldIDMap) Size() int 1331 ``` 1332 1333 Size returns the size of the map 1334 1335 ## type FieldNameMap 1336 1337 FieldNameMap is a map for field name and field descriptor 1338 1339 ```go 1340 type FieldNameMap struct { 1341 // contains filtered or unexported fields 1342 } 1343 ``` 1344 1345 ### func \(FieldNameMap\) All 1346 1347 ```go 1348 func (ft FieldNameMap) All() []*FieldDescriptor 1349 ``` 1350 1351 All returns all field descriptors 1352 1353 ### func \(\*FieldNameMap\) Build 1354 1355 ```go 1356 func (ft *FieldNameMap) Build() 1357 ``` 1358 1359 Build builds the map. It will try to build a trie tree if the dispersion of keys is higher enough \(min\). 1360 1361 ### func \(FieldNameMap\) Get 1362 1363 ```go 1364 func (ft FieldNameMap) Get(k string) *FieldDescriptor 1365 ``` 1366 1367 Get gets the field descriptor for the given key 1368 1369 ### func \(\*FieldNameMap\) Set 1370 1371 ```go 1372 func (ft *FieldNameMap) Set(key string, field *FieldDescriptor) (exist bool) 1373 ``` 1374 1375 Set sets the field descriptor for the given key 1376 1377 ### func \(FieldNameMap\) Size 1378 1379 ```go 1380 func (ft FieldNameMap) Size() int 1381 ``` 1382 1383 Size returns the size of the map 1384 1385 ## type FunctionDescriptor 1386 1387 FunctionDescriptor idl function descriptor 1388 1389 ```go 1390 type FunctionDescriptor struct { 1391 // contains filtered or unexported fields 1392 } 1393 ``` 1394 1395 ### func GetFnDescFromFile 1396 1397 ```go 1398 func GetFnDescFromFile(filePath, fnName string, opts Options) *FunctionDescriptor 1399 ``` 1400 1401 GetFnDescFromFile get a fucntion descriptor from idl path \(relative to your git root\) and the function name 1402 1403 ### func \(FunctionDescriptor\) Annotations 1404 1405 ```go 1406 func (f FunctionDescriptor) Annotations() map[string][]string 1407 ``` 1408 1409 Annotations returns the annotations of the function 1410 1411 ### func \(FunctionDescriptor\) Endpoints 1412 1413 ```go 1414 func (f FunctionDescriptor) Endpoints() []http.Endpoint 1415 ``` 1416 1417 Endpoints returns the http endpoints of the function 1418 1419 ### func \(FunctionDescriptor\) HasRequestBase 1420 1421 ```go 1422 func (f FunctionDescriptor) HasRequestBase() bool 1423 ``` 1424 1425 HasRequestBase tells if the function has a base.Base field 1426 1427 ### func \(FunctionDescriptor\) Name 1428 1429 ```go 1430 func (f FunctionDescriptor) Name() string 1431 ``` 1432 1433 Name returns the name of the function 1434 1435 ### func \(FunctionDescriptor\) Oneway 1436 1437 ```go 1438 func (f FunctionDescriptor) Oneway() bool 1439 ``` 1440 1441 Oneway tells if the function is oneway type 1442 1443 ### func \(FunctionDescriptor\) Request 1444 1445 ```go 1446 func (f FunctionDescriptor) Request() *TypeDescriptor 1447 ``` 1448 1449 Request returns the request type descriptor of the function The request arguements is mapped with arguement id and name 1450 1451 ### func \(FunctionDescriptor\) Response 1452 1453 ```go 1454 func (f FunctionDescriptor) Response() *TypeDescriptor 1455 ``` 1456 1457 Response returns the response type descriptor of the function The response arguements is mapped with arguement id 1458 1459 ## type HttpMapping 1460 1461 HTTPMapping is used to convert http value while running convertion. See also: thrift/annotation/http\_mapping.go 1462 1463 ```go 1464 type HttpMapping interface { 1465 // Request get a http value from req 1466 Request(ctx context.Context, req http.RequestGetter, field *FieldDescriptor) (string, error) 1467 1468 // Response set a http value into resp 1469 Response(ctx context.Context, resp http.ResponseSetter, field *FieldDescriptor, val string) error 1470 1471 // RawEncoding indicates the encoding of the value, it should be meta.EncodingText by default 1472 Encoding() meta.Encoding 1473 } 1474 ``` 1475 1476 ## type KeyMapping 1477 1478 KeyMapping is used to convert field key while parsing idl. See also: thrift/annotation/key\_mapping.go 1479 1480 ```go 1481 type KeyMapping interface { 1482 // Map key to new key 1483 Map(ctx context.Context, key string) string 1484 } 1485 ``` 1486 1487 ## type OptionMapping 1488 1489 OptionMapping is used to convert thrift.Options while parsing idl. See also: thrift/annotation/option\_mapping.go 1490 1491 ```go 1492 type OptionMapping interface { 1493 // Map options to new options 1494 Map(ctx context.Context, opts Options) Options 1495 } 1496 ``` 1497 1498 ## type Options 1499 1500 Options is options for parsing thrift IDL. 1501 1502 ```go 1503 type Options struct { 1504 // ParseServiceMode indicates how to parse service. 1505 ParseServiceMode meta.ParseServiceMode 1506 1507 // MapFieldWay indicates StructDescriptor.FieldByKey() uses alias to map field. 1508 // By default, we use alias to map, and alias always equals to field name if not given. 1509 MapFieldWay meta.MapFieldWay 1510 1511 // ParseFieldRandomRate indicates whether to parse partial fields and is only used for mock test. 1512 // The value means the possibility of randomly parse and embed one field into StructDescriptor. 1513 // It must be within (0, 1], and 0 means always parse all fields. 1514 ParseFieldRandomRate float64 1515 1516 // ParseEnumAsInt64 indicates whether to parse enum as I64 (default I32). 1517 ParseEnumAsInt64 bool 1518 1519 // SetOptionalBitmap indicates to set bitmap for optional fields 1520 SetOptionalBitmap bool 1521 1522 // UseDefaultValue indicates to parse and store default value defined on IDL fields. 1523 UseDefaultValue bool 1524 1525 // ParseFunctionMode indicates to parse only response or request for a function 1526 ParseFunctionMode meta.ParseFunctionMode 1527 1528 // EnableThriftBase indicates to explictly handle thrift/base (see README.md) fields. 1529 // One field is identified as a thrift base if it satisfies **BOTH** of the following conditions: 1530 // 1. Its type is 'base.Base' (for request base) or 'base.BaseResp' (for response base); 1531 // 2. it is on the top layer of the root struct of one function. 1532 EnableThriftBase bool 1533 } 1534 ``` 1535 1536 ### func NewDefaultOptions 1537 1538 ```go 1539 func NewDefaultOptions() Options 1540 ``` 1541 1542 NewDefaultOptions creates a default Options. 1543 1544 ### func \(Options\) NewDescriptorFromContentWithMethod 1545 1546 ```go 1547 func (opts Options) NewDescriptorFromContentWithMethod(ctx context.Context, path, content string, includes map[string]string, isAbsIncludePath bool, methods ...string) (*ServiceDescriptor, error) 1548 ``` 1549 1550 NewDescritorFromContentWithMethod creates a ServiceDescriptor from a thrift content and its includes, but only parse specific methods. 1551 1552 ### func \(Options\) NewDescriptorFromPathWithMethod 1553 1554 ```go 1555 func (opts Options) NewDescriptorFromPathWithMethod(ctx context.Context, path string, includeDirs []string, methods ...string) (*ServiceDescriptor, error) 1556 ``` 1557 1558 NewDescritorFromContent creates a ServiceDescriptor from a thrift path and its includes, with specific methods. If methods is empty, all methods will be parsed. The includeDirs is used to find the include files. 1559 1560 ### func \(Options\) NewDescritorFromContent 1561 1562 ```go 1563 func (opts Options) NewDescritorFromContent(ctx context.Context, path, content string, includes map[string]string, isAbsIncludePath bool) (*ServiceDescriptor, error) 1564 ``` 1565 1566 NewDescritorFromContent creates a ServiceDescriptor from a thrift content and its includes, which uses the default options. path is the main thrift file path, content is the main thrift file content. includes is the thrift file content map, and its keys are specific including thrift file path. isAbsIncludePath indicates whether these keys of includes are absolute path. If true, the include path will be joined with the main thrift file path. 1567 1568 ### func \(Options\) NewDescritorFromPath 1569 1570 ```go 1571 func (opts Options) NewDescritorFromPath(ctx context.Context, path string, includeDirs ...string) (*ServiceDescriptor, error) 1572 ``` 1573 1574 NewDescritorFromContent creates a ServiceDescriptor from a thrift path and its includes, which uses the given options. The includeDirs is used to find the include files. 1575 1576 ## type ParseTarget 1577 1578 ParseTarget indicates the target to parse 1579 1580 ```go 1581 type ParseTarget uint8 1582 ``` 1583 1584 ```go 1585 const ( 1586 Request ParseTarget = iota 1587 Response 1588 Exception 1589 ) 1590 ``` 1591 1592 ## type Requireness 1593 1594 Requireness is the requireness of a field. See also https://thrift.apache.org/docs/idl.html 1595 1596 ```go 1597 type Requireness uint8 1598 ``` 1599 1600 ```go 1601 const ( 1602 // OptionalRequireness means the field is optional 1603 OptionalRequireness Requireness = 0 1604 // DefaultRequireness means the field is default-requireness 1605 DefaultRequireness Requireness = 1 1606 // RequiredRequireness means the field is required 1607 RequiredRequireness Requireness = 2 1608 ) 1609 ``` 1610 1611 ## type RequiresBitmap 1612 1613 RequiresBitmap is a bitmap to mark fields 1614 1615 ```go 1616 type RequiresBitmap []uint64 1617 ``` 1618 1619 ### func NewRequiresBitmap 1620 1621 ```go 1622 func NewRequiresBitmap() *RequiresBitmap 1623 ``` 1624 1625 NewRequiresBitmap get bitmap from pool, if pool is empty, create a new one WARN: memory from pool maybe dirty\! 1626 1627 ### func \(RequiresBitmap\) CheckRequires 1628 1629 ```go 1630 func (b RequiresBitmap) CheckRequires(desc *StructDescriptor, writeDefault bool, handler func(field *FieldDescriptor) error) error 1631 ``` 1632 1633 CheckRequires scan every bit of the bitmap. When a bit is marked, it will: \- if the corresponding field is required\-requireness, it reports error \- if the corresponding is not required\-requireness but writeDefault is true, it will call handler to handle this field 1634 1635 ### func \(RequiresBitmap\) CopyTo 1636 1637 ```go 1638 func (b RequiresBitmap) CopyTo(to *RequiresBitmap) 1639 ``` 1640 1641 CopyTo copy the bitmap to a given bitmap 1642 1643 ### func \(RequiresBitmap\) HandleRequires 1644 1645 ```go 1646 func (b RequiresBitmap) HandleRequires(desc *StructDescriptor, writeRquired bool, writeDefault bool, writeOptional bool, handler func(field *FieldDescriptor) error) error 1647 ``` 1648 1649 CheckRequires scan every bit of the bitmap. When a bit is marked, it will: \- if the corresponding field is required\-requireness and writeRquired is true, it will call handler to handle this field, otherwise report error \- if the corresponding is default\-requireness and writeDefault is true, it will call handler to handle this field \- if the corresponding is optional\-requireness and writeOptional is true, it will call handler to handle this field 1650 1651 ### func \(RequiresBitmap\) IsSet 1652 1653 ```go 1654 func (b RequiresBitmap) IsSet(id FieldID) bool 1655 ``` 1656 1657 IsSet tells if the bit corresponding the given id is marked 1658 1659 ### func \(\*RequiresBitmap\) Set 1660 1661 ```go 1662 func (b *RequiresBitmap) Set(id FieldID, val Requireness) 1663 ``` 1664 1665 Set mark the bit corresponding the given id, with the given requireness \- RequiredRequireness|DefaultRequireness mark the bit as 1 \- OptionalRequireness mark the bit as 0 1666 1667 ## type ServiceDescriptor 1668 1669 ServiceDescriptor is the runtime descriptor of a service 1670 1671 ```go 1672 type ServiceDescriptor struct { 1673 // contains filtered or unexported fields 1674 } 1675 ``` 1676 1677 ### func NewDescritorFromContent 1678 1679 ```go 1680 func NewDescritorFromContent(ctx context.Context, path, content string, includes map[string]string, isAbsIncludePath bool) (*ServiceDescriptor, error) 1681 ``` 1682 1683 NewDescritorFromContent behaviors like NewDescritorFromPath, besides it uses DefaultOptions. 1684 1685 <details><summary>Example</summary> 1686 <p> 1687 1688 ```go 1689 { 1690 path := "a/b/main.thrift" 1691 content := ` 1692 include "base/base.thrift" 1693 namespace go test.server 1694 1695 service InboxService { 1696 base.BaseResp ExampleMethod(1: base.Base req) 1697 }` 1698 base := ` 1699 namespace py base 1700 namespace go base 1701 namespace java com.bytedance.thrift.base 1702 1703 struct TrafficEnv { 1704 1: bool Open = false, 1705 2: string Env = "", 1706 } 1707 1708 struct Base { 1709 1: string LogID = "", 1710 2: string Caller = "", 1711 3: string Addr = "", 1712 4: string Client = "", 1713 5: optional TrafficEnv TrafficEnv, 1714 6: optional map<string, string> Extra, 1715 } 1716 1717 struct BaseResp { 1718 1: string StatusMessage = "", 1719 2: i32 StatusCode = 0, 1720 3: optional map<string, string> Extra, 1721 } 1722 ` 1723 1724 includes := map[string]string{ 1725 path: content, 1726 "a/b/base/base.thrift": base, 1727 } 1728 1729 p1, err := NewDescritorFromContent(context.Background(), path, content, includes, true) 1730 if err != nil { 1731 panic(err) 1732 } 1733 r1, _ := p1.LookupFunctionByMethod("ExampleMethod") 1734 fmt.Printf("%#v\n", r1.Response()) 1735 1736 delete(includes, "a/b/base/base.thrift") 1737 includes["base/base.thrift"] = base 1738 1739 p2, err := Options{ 1740 ParseFunctionMode: meta.ParseRequestOnly, 1741 }.NewDescritorFromContent(context.Background(), path, content, includes, false) 1742 if err != nil { 1743 panic(err) 1744 } 1745 r2, _ := p2.LookupFunctionByMethod("ExampleMethod") 1746 fmt.Printf("%#v\n", r2.Response()) 1747 } 1748 ``` 1749 1750 </p> 1751 </details> 1752 1753 ### func NewDescritorFromPath 1754 1755 ```go 1756 func NewDescritorFromPath(ctx context.Context, path string, includeDirs ...string) (*ServiceDescriptor, error) 1757 ``` 1758 1759 NewDescritorFromPath behaviors like NewDescritorFromPath, besides it uses DefaultOptions. 1760 1761 <details><summary>Example</summary> 1762 <p> 1763 1764 ```go 1765 { 1766 1767 p1, err := NewDescritorFromPath(context.Background(), "../testdata/idl/example.thrift") 1768 if err != nil { 1769 panic(err) 1770 } 1771 r1, _ := p1.LookupFunctionByMethod("ExampleMethod") 1772 fmt.Printf("%#v\n", r1.Response()) 1773 1774 p2, err := Options{ 1775 ParseFunctionMode: meta.ParseRequestOnly, 1776 }.NewDescritorFromPath(context.Background(), "../testdata/idl/example.thrift") 1777 if err != nil { 1778 panic(err) 1779 } 1780 r2, _ := p2.LookupFunctionByMethod("ExampleMethod") 1781 fmt.Printf("%#v\n", r2.Response()) 1782 } 1783 ``` 1784 1785 </p> 1786 </details> 1787 1788 ### func \(ServiceDescriptor\) Annotations 1789 1790 ```go 1791 func (s ServiceDescriptor) Annotations() map[string][]string 1792 ``` 1793 1794 Annotations returns the annotations of a service 1795 1796 ### func \(ServiceDescriptor\) Functions 1797 1798 ```go 1799 func (s ServiceDescriptor) Functions() map[string]*FunctionDescriptor 1800 ``` 1801 1802 Functions returns all functions in the service 1803 1804 ### func \(\*ServiceDescriptor\) LookupFunctionByMethod 1805 1806 ```go 1807 func (s *ServiceDescriptor) LookupFunctionByMethod(method string) (*FunctionDescriptor, error) 1808 ``` 1809 1810 LookupFunctionByMethod lookup function by method name 1811 1812 ### func \(ServiceDescriptor\) Name 1813 1814 ```go 1815 func (s ServiceDescriptor) Name() string 1816 ``` 1817 1818 Name returns the name of the service 1819 1820 ## type StructDescriptor 1821 1822 StructDescriptor is the runtime descriptor of a STRUCT type 1823 1824 ```go 1825 type StructDescriptor struct { 1826 // contains filtered or unexported fields 1827 } 1828 ``` 1829 1830 ### func \(StructDescriptor\) FieldById 1831 1832 ```go 1833 func (s StructDescriptor) FieldById(id FieldID) *FieldDescriptor 1834 ``` 1835 1836 FieldById finds the field by field id 1837 1838 ### func \(StructDescriptor\) FieldByKey 1839 1840 ```go 1841 func (s StructDescriptor) FieldByKey(k string) (field *FieldDescriptor) 1842 ``` 1843 1844 #### FieldByName finds the field by key 1845 1846 NOTICE: Options.MapFieldWay can influence the behavior of this method. ep: if Options.MapFieldWay is MapFieldWayName, then field names should be used as key. 1847 1848 ### func \(StructDescriptor\) Fields 1849 1850 ```go 1851 func (s StructDescriptor) Fields() []*FieldDescriptor 1852 ``` 1853 1854 Fields returns all fields in the struct 1855 1856 ### func \(StructDescriptor\) GetRequestBase 1857 1858 ```go 1859 func (s StructDescriptor) GetRequestBase() *FieldDescriptor 1860 ``` 1861 1862 GetRequestBase returns the base.Base field of a STRUCT 1863 1864 ### func \(StructDescriptor\) GetResponseBase 1865 1866 ```go 1867 func (s StructDescriptor) GetResponseBase() *FieldDescriptor 1868 ``` 1869 1870 GetResponseBase returns the base.BaseResp field of a STRUCT 1871 1872 ### func \(StructDescriptor\) HttpMappingFields 1873 1874 ```go 1875 func (s StructDescriptor) HttpMappingFields() []*FieldDescriptor 1876 ``` 1877 1878 GetHttpMappingFields returns the fields with http\-mapping annotations 1879 1880 ### func \(StructDescriptor\) Len 1881 1882 ```go 1883 func (s StructDescriptor) Len() int 1884 ``` 1885 1886 Len returns the number of fields in the struct 1887 1888 ### func \(StructDescriptor\) Name 1889 1890 ```go 1891 func (s StructDescriptor) Name() string 1892 ``` 1893 1894 Name returns the name of the struct 1895 1896 ### func \(StructDescriptor\) Requires 1897 1898 ```go 1899 func (s StructDescriptor) Requires() RequiresBitmap 1900 ``` 1901 1902 Fields returns requireness bitmap in the struct. By default, only Requred and Default fields are marked. 1903 1904 ## type TMessageType 1905 1906 TMessageType is the type of message 1907 1908 ```go 1909 type TMessageType int32 1910 ``` 1911 1912 ```go 1913 const ( 1914 INVALID_TMESSAGE_TYPE TMessageType = 0 1915 CALL TMessageType = 1 1916 REPLY TMessageType = 2 1917 EXCEPTION TMessageType = 3 1918 ONEWAY TMessageType = 4 1919 ) 1920 ``` 1921 1922 ## type Type 1923 1924 Type constants in the Thrift protocol 1925 1926 ```go 1927 type Type byte 1928 ``` 1929 1930 built\-in Types 1931 1932 ```go 1933 const ( 1934 STOP Type = 0 1935 VOID Type = 1 1936 BOOL Type = 2 1937 BYTE Type = 3 1938 I08 Type = 3 1939 DOUBLE Type = 4 1940 I16 Type = 6 1941 I32 Type = 8 1942 I64 Type = 10 1943 STRING Type = 11 1944 // UTF7 Type = 11 1945 STRUCT Type = 12 1946 MAP Type = 13 1947 SET Type = 14 1948 LIST Type = 15 1949 UTF8 Type = 16 1950 UTF16 Type = 17 1951 1952 ERROR Type = 255 1953 ) 1954 ``` 1955 1956 ### func FromThriftTType 1957 1958 ```go 1959 func FromThriftTType(t thrift.TType) Type 1960 ``` 1961 1962 FromThriftTType converts apache/thrift.TType to Type 1963 1964 ### func \(Type\) IsComplex 1965 1966 ```go 1967 func (p Type) IsComplex() bool 1968 ``` 1969 1970 IsComplex tells if the type is one of STRUCT, MAP, SET, LIST 1971 1972 ### func \(Type\) IsInt 1973 1974 ```go 1975 func (p Type) IsInt() bool 1976 ``` 1977 1978 IsInt tells if the type is one of I08, I16, I32, I64 1979 1980 ### func \(Type\) String 1981 1982 ```go 1983 func (p Type) String() string 1984 ``` 1985 1986 String for format and print 1987 1988 ### func \(Type\) ToThriftTType 1989 1990 ```go 1991 func (p Type) ToThriftTType() thrift.TType 1992 ``` 1993 1994 ToThriftTType converts Type to apache/thrift.TType 1995 1996 ### func \(Type\) Valid 1997 1998 ```go 1999 func (p Type) Valid() bool 2000 ``` 2001 2002 ## type TypeDescriptor 2003 2004 TypeDescriptor is the runtime descriptor of a thrift type 2005 2006 ```go 2007 type TypeDescriptor struct { 2008 // contains filtered or unexported fields 2009 } 2010 ``` 2011 2012 ### func FnRequest 2013 2014 ```go 2015 func FnRequest(fn *FunctionDescriptor) *TypeDescriptor 2016 ``` 2017 2018 FnRequest We assume the request only have one argument and the only argument it the type we want. 2019 2020 ### func FnResponse 2021 2022 ```go 2023 func FnResponse(fn *FunctionDescriptor) *TypeDescriptor 2024 ``` 2025 2026 FnResponse get the normal response type 2027 2028 ### func \(TypeDescriptor\) Elem 2029 2030 ```go 2031 func (d TypeDescriptor) Elem() *TypeDescriptor 2032 ``` 2033 2034 Elem returns the element type descriptor of a LIST, SET or MAP type 2035 2036 ### func \(TypeDescriptor\) IsBinary 2037 2038 ```go 2039 func (d TypeDescriptor) IsBinary() bool 2040 ``` 2041 2042 IsBinary tells if the type is binary type \(\[\]byte\) 2043 2044 ### func \(TypeDescriptor\) Key 2045 2046 ```go 2047 func (d TypeDescriptor) Key() *TypeDescriptor 2048 ``` 2049 2050 Key returns the key type descriptor of a MAP type 2051 2052 ### func \(TypeDescriptor\) Name 2053 2054 ```go 2055 func (d TypeDescriptor) Name() string 2056 ``` 2057 2058 Name returns the name of the descriptor for struct, it is the struct name; for build\-in type, it is the type name. 2059 2060 ### func \(TypeDescriptor\) Struct 2061 2062 ```go 2063 func (d TypeDescriptor) Struct() *StructDescriptor 2064 ``` 2065 2066 Struct returns the struct type descriptor of a STRUCT type 2067 2068 ### func \(TypeDescriptor\) Type 2069 2070 ```go 2071 func (d TypeDescriptor) Type() Type 2072 ``` 2073 2074 Type returns the build\-in type of the descriptor 2075 2076 ## type ValueMapping 2077 2078 ValueMapping is used to convert thrift value while running convertion. See also: thrift/annotation/value\_mapping.go 2079 2080 ```go 2081 type ValueMapping interface { 2082 // Read thrift value from p and convert it into out 2083 Read(ctx context.Context, p *BinaryProtocol, field *FieldDescriptor, out *[]byte) error 2084 2085 // Write thrift value into p, which is converted from in 2086 Write(ctx context.Context, p *BinaryProtocol, field *FieldDescriptor, in []byte) error 2087 } 2088 ``` 2089 2090 2091 2092 Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)