Skip to content

Latest commit

 

History

History
893 lines (605 loc) · 23.6 KB

README.md

File metadata and controls

893 lines (605 loc) · 23.6 KB

proto

import "github.com/cloudwego/dynamicgo/proto"

Index

Variables

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 (*FieldDescriptor) IsList

func (f *FieldDescriptor) IsList() bool

func (*FieldDescriptor) IsMap

func (f *FieldDescriptor) IsMap() bool

func (*FieldDescriptor) JSONName

func (f *FieldDescriptor) JSONName() string

func (*FieldDescriptor) Kind

func (f *FieldDescriptor) Kind() ProtoKind

func (*FieldDescriptor) MapKey

func (f *FieldDescriptor) MapKey() *TypeDescriptor

func (*FieldDescriptor) MapValue

func (f *FieldDescriptor) MapValue() *TypeDescriptor

func (*FieldDescriptor) Message

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 (*FieldDescriptor) Name

func (f *FieldDescriptor) Name() string

func (*FieldDescriptor) Number

func (f *FieldDescriptor) Number() FieldNumber

func (*FieldDescriptor) Type

func (f *FieldDescriptor) Type() *TypeDescriptor

FieldNameMap is a map for field name and field descriptor

type FieldNameMap struct {
    // contains filtered or unexported fields
}

func (FieldNameMap) All

func (ft FieldNameMap) All() []*FieldDescriptor

All returns all field descriptors

func (*FieldNameMap) Build

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 (FieldNameMap) Get

func (ft FieldNameMap) Get(k string) *FieldDescriptor

Get gets the field descriptor for the given key

func (*FieldNameMap) Set

func (ft *FieldNameMap) Set(key string, field *FieldDescriptor) (exist bool)

Set sets the field descriptor for the given key

func (FieldNameMap) Size

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 (FieldNumberMap) All

func (fd FieldNumberMap) All() (ret []*FieldDescriptor)

All returns all field descriptors

func (FieldNumberMap) Get

func (fd FieldNumberMap) Get(id FieldNumber) *FieldDescriptor

Get gets the field descriptor for the given id

func (*FieldNumberMap) Set

func (fd *FieldNumberMap) Set(id FieldNumber, f *FieldDescriptor)

Set sets the field descriptor for the given id

func (FieldNumberMap) Size

func (fd FieldNumberMap) Size() int

Size returns the size of the map

type MessageDescriptor struct {
    // contains filtered or unexported fields
}

func (*MessageDescriptor) ByJSONName

func (m *MessageDescriptor) ByJSONName(name string) *FieldDescriptor

func (*MessageDescriptor) ByName

func (m *MessageDescriptor) ByName(name string) *FieldDescriptor

func (*MessageDescriptor) ByNumber

func (m *MessageDescriptor) ByNumber(id FieldNumber) *FieldDescriptor

func (*MessageDescriptor) FieldsCount

func (m *MessageDescriptor) FieldsCount() int

func (*MessageDescriptor) Name

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 (*MethodDescriptor) Input

func (m *MethodDescriptor) Input() *TypeDescriptor

func (*MethodDescriptor) Name

func (m *MethodDescriptor) Name() string

func (*MethodDescriptor) Output

func (m *MethodDescriptor) Output() *TypeDescriptor

type Number

define Number = protowire.Number (int32)

type Number = protowire.Number

type Options

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 (Options) NewDescriptorFromPath

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 (*ServiceDescriptor) LookupMethodByName

func (s *ServiceDescriptor) LookupMethodByName(name string) *MethodDescriptor

func (*ServiceDescriptor) Methods

func (s *ServiceDescriptor) Methods() map[string]*MethodDescriptor

func (*ServiceDescriptor) Name

func (s *ServiceDescriptor) Name() string

type Type

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 (Type) IsComplex

func (p Type) IsComplex() bool

IsComplex tells if the type is one of STRUCT, MAP, SET, LIST

func (Type) IsInt

func (p Type) IsInt() bool

IsInt containing isUint

func (Type) IsPacked

func (p Type) IsPacked() bool

func (Type) IsUint

func (p Type) IsUint() bool

func (Type) NeedVarint

func (p Type) NeedVarint() bool

check if the type need Varint encoding

func (Type) String

func (p Type) String() string

String for format and print

func (Type) TypeToKind

func (p Type) TypeToKind() ProtoKind

func (Type) Valid

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 (*TypeDescriptor) BaseId

func (t *TypeDescriptor) BaseId() FieldNumber

func (*TypeDescriptor) Elem

func (t *TypeDescriptor) Elem() *TypeDescriptor

func (*TypeDescriptor) IsList

func (f *TypeDescriptor) IsList() bool

func (*TypeDescriptor) IsMap

func (f *TypeDescriptor) IsMap() bool

func (*TypeDescriptor) IsPacked

func (t *TypeDescriptor) IsPacked() bool

func (*TypeDescriptor) Key

func (t *TypeDescriptor) Key() *TypeDescriptor

func (*TypeDescriptor) Message

func (t *TypeDescriptor) Message() *MessageDescriptor

func (*TypeDescriptor) Name

func (f *TypeDescriptor) Name() string

func (*TypeDescriptor) Type

func (t *TypeDescriptor) Type() Type

func (*TypeDescriptor) WireType

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 (WireType) String

func (p WireType) String() string

Generated by gomarkdoc