import "github.com/cloudwego/dynamicgo/proto"
map from proto.ProtoKind to proto.WireType
var Kind2Wire = map[ProtoKind]WireType{
BoolKind: VarintType,
EnumKind: VarintType,
Int32Kind: VarintType,
Sint32Kind: VarintType,
Uint32Kind: VarintType,
Int64Kind: VarintType,
Sint64Kind: VarintType,
Uint64Kind: VarintType,
Sfixed32Kind: Fixed32Type,
Fixed32Kind: Fixed32Type,
FloatKind: Fixed32Type,
Sfixed64Kind: Fixed64Type,
Fixed64Kind: Fixed64Type,
DoubleKind: Fixed64Type,
StringKind: BytesType,
BytesKind: BytesType,
MessageKind: BytesType,
GroupKind: StartGroupType,
}
type EnumNumber int32
type FieldDescriptor struct {
// contains filtered or unexported fields
}
func (f *FieldDescriptor) IsList() bool
func (f *FieldDescriptor) IsMap() bool
func (f *FieldDescriptor) JSONName() string
func (f *FieldDescriptor) Kind() ProtoKind
func (f *FieldDescriptor) MapKey() *TypeDescriptor
func (f *FieldDescriptor) MapValue() *TypeDescriptor
func (f *FieldDescriptor) Message() *MessageDescriptor
when List+Message it can get message element descriptor when Map it can get map key-value entry massage descriptor when Message it can get sub message descriptor
func (f *FieldDescriptor) Name() string
func (f *FieldDescriptor) Number() FieldNumber
func (f *FieldDescriptor) Type() *TypeDescriptor
FieldNameMap is a map for field name and field descriptor
type FieldNameMap struct {
// contains filtered or unexported fields
}
func (ft FieldNameMap) All() []*FieldDescriptor
All returns all field descriptors
func (ft *FieldNameMap) Build()
Build builds the map. It will try to build a trie tree if the dispersion of keys is higher enough (min).
func (ft FieldNameMap) Get(k string) *FieldDescriptor
Get gets the field descriptor for the given key
func (ft *FieldNameMap) Set(key string, field *FieldDescriptor) (exist bool)
Set sets the field descriptor for the given key
func (ft FieldNameMap) Size() int
Size returns the size of the map
type FieldNumber int32
reserved field number min-max ranges in a proto message
const (
MinValidNumber FieldNumber = 1
FirstReservedNumber FieldNumber = 19000
LastReservedNumber FieldNumber = 19999
MaxValidNumber FieldNumber = 1<<29 - 1
DefaultRecursionLimit = 10000
)
FieldIDMap is a map from field id to field descriptor
type FieldNumberMap struct {
// contains filtered or unexported fields
}
func (fd FieldNumberMap) All() (ret []*FieldDescriptor)
All returns all field descriptors
func (fd FieldNumberMap) Get(id FieldNumber) *FieldDescriptor
Get gets the field descriptor for the given id
func (fd *FieldNumberMap) Set(id FieldNumber, f *FieldDescriptor)
Set sets the field descriptor for the given id
func (fd FieldNumberMap) Size() int
Size returns the size of the map
type MessageDescriptor struct {
// contains filtered or unexported fields
}
func (m *MessageDescriptor) ByJSONName(name string) *FieldDescriptor
func (m *MessageDescriptor) ByName(name string) *FieldDescriptor
func (m *MessageDescriptor) ByNumber(id FieldNumber) *FieldDescriptor
func (m *MessageDescriptor) FieldsCount() int
func (m *MessageDescriptor) Name() string
type MethodDescriptor struct {
// contains filtered or unexported fields
}
func GetFnDescFromFile(filePath, fnName string, opts Options, includeDirs ...string) *MethodDescriptor
GetFnDescFromFile get a fucntion descriptor from idl path (relative to your git root) and the function name
func (m *MethodDescriptor) Input() *TypeDescriptor
func (m *MethodDescriptor) Name() string
func (m *MethodDescriptor) Output() *TypeDescriptor
define Number = protowire.Number (int32)
type Number = protowire.Number
Options is options for parsing thrift IDL.
type Options struct {
// ParseServiceMode indicates how to parse service.
ParseServiceMode meta.ParseServiceMode
MapFieldWay meta.MapFieldWay // not implemented.
ParseFieldRandomRate float64 // not implemented.
ParseEnumAsInt64 bool // not implemented.
SetOptionalBitmap bool // not implemented.
UseDefaultValue bool // not implemented.
ParseFunctionMode meta.ParseFunctionMode // not implemented.
EnableProtoBase bool // not implemented.
}
func NewDefaultOptions() Options
NewDefaultOptions creates a default Options.
func (opts Options) NewDesccriptorFromContent(ctx context.Context, path, content string, includes map[string]string, importDirs ...string) (*ServiceDescriptor, error)
func (opts Options) NewDescriptorFromPath(ctx context.Context, path string, importDirs ...string) (*ServiceDescriptor, error)
NewDescritorFromContent creates a ServiceDescriptor from a proto path and its imports, which uses the given options. The importDirs is used to find the include files.
ParseTarget indicates the target to parse
type ParseTarget uint8
const (
Request ParseTarget = iota
Response
Exception
)
define ProtoKind = protoreflect.Kind (int8)
type ProtoKind = protoreflect.Kind
const (
DoubleKind ProtoKind = iota + 1
FloatKind
Int64Kind
Uint64Kind
Int32Kind
Fixed64Kind
Fixed32Kind
BoolKind
StringKind
GroupKind
MessageKind
BytesKind
Uint32Kind
EnumKind
Sfixed32Kind
Sfixed64Kind
Sint32Kind
Sint64Kind
)
type ServiceDescriptor struct {
// contains filtered or unexported fields
}
func NewDescritorFromContent(ctx context.Context, path, content string, includes map[string]string, importDirs ...string) (*ServiceDescriptor, error)
NewDescritorFromContent behaviors like NewDescritorFromPath, besides it uses DefaultOptions.
func NewDescritorFromPath(ctx context.Context, path string, importDirs ...string) (*ServiceDescriptor, error)
NewDescritorFromPath behaviors like NewDescritorFromPath, besides it uses DefaultOptions.
func (s *ServiceDescriptor) LookupMethodByName(name string) *MethodDescriptor
func (s *ServiceDescriptor) Methods() map[string]*MethodDescriptor
func (s *ServiceDescriptor) Name() string
Node type (uint8) mapping ProtoKind the same value, except for UNKNOWN, LIST, MAP, ERROR
type Type uint8
const (
UNKNOWN Type = 0 // unknown field type
DOUBLE Type = 1
FLOAT Type = 2
INT64 Type = 3
UINT64 Type = 4
INT32 Type = 5
FIX64 Type = 6
FIX32 Type = 7
BOOL Type = 8
STRING Type = 9
GROUP Type = 10 // deprecated
MESSAGE Type = 11
BYTE Type = 12
UINT32 Type = 13
ENUM Type = 14
SFIX32 Type = 15
SFIX64 Type = 16
SINT32 Type = 17
SINT64 Type = 18
LIST Type = 19
MAP Type = 20
ERROR Type = 255
)
func FromProtoKindToType(kind ProtoKind, isList bool, isMap bool) Type
FromProtoKindTType converts ProtoKind to Type
func (p Type) IsComplex() bool
IsComplex tells if the type is one of STRUCT, MAP, SET, LIST
func (p Type) IsInt() bool
IsInt containing isUint
func (p Type) IsPacked() bool
func (p Type) IsUint() bool
func (p Type) NeedVarint() bool
check if the type need Varint encoding
func (p Type) String() string
String for format and print
func (p Type) TypeToKind() ProtoKind
func (p Type) Valid() bool
type TypeDescriptor struct {
// contains filtered or unexported fields
}
func FnRequest(fn *MethodDescriptor) *TypeDescriptor
FnRequest get the normal requestDescriptor
func FnResponse(fn *MethodDescriptor) *TypeDescriptor
FnResponse get hte normal responseDescriptor
func (t *TypeDescriptor) BaseId() FieldNumber
func (t *TypeDescriptor) Elem() *TypeDescriptor
func (f *TypeDescriptor) IsList() bool
func (f *TypeDescriptor) IsMap() bool
func (t *TypeDescriptor) IsPacked() bool
func (t *TypeDescriptor) Key() *TypeDescriptor
func (t *TypeDescriptor) Message() *MessageDescriptor
func (f *TypeDescriptor) Name() string
func (t *TypeDescriptor) Type() Type
func (f *TypeDescriptor) WireType() WireType
protobuf encoding wire type
type WireType int8
const (
VarintType WireType = 0
Fixed32Type WireType = 5
Fixed64Type WireType = 1
BytesType WireType = 2
StartGroupType WireType = 3 // deprecated
EndGroupType WireType = 4 // deprecated
)
func (p WireType) String() string
Generated by gomarkdoc
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。