types

package
v0.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertMap added in v0.3.0

func ConvertMap[K, Rk comparable, V, Rv any](tm map[K]V, f func(tk K, tv V) (Rk, Rv)) map[Rk]Rv

ConvertMap is used by the generated code.

func ConvertSlice

func ConvertSlice[T, R any](ts []T, f func(t T) R) []R

ConvertSlice is used by the generated code.

func ErrorToString

func ErrorToString(err error) string

ErrorToString is used in the generated code to convert an error to a string.

func OutputDir

func OutputDir(sourceDir string) string

func PackageName

func PackageName(sourcePackagePath string) string

func PackagePath

func PackagePath(sourcePackagePath string) string

func StringToError

func StringToError(s string) error

StringToError is used in the generated code to convert a string to an error.

Types

type Castable

type Castable struct {
	PbType_  jen.Code // nolint
	MirType_ jen.Code // nolint
}

Castable is used when the types used by protoc-generated code and Mir-generated code can be directly cast to one another.

func (Castable) MirType

func (t Castable) MirType() *jen.Statement

func (Castable) PbType

func (t Castable) PbType() *jen.Statement

func (Castable) Same

func (t Castable) Same() bool

func (Castable) ToMir

func (t Castable) ToMir(code jen.Code) *jen.Statement

func (Castable) ToPb

func (t Castable) ToPb(code jen.Code) *jen.Statement

type Error

type Error struct{}

Error represents a string field in a message annotated with [(mir.type) = "error"].

func (Error) MirType

func (t Error) MirType() *jen.Statement

func (Error) PbType

func (t Error) PbType() *jen.Statement

func (Error) Same

func (t Error) Same() bool

func (Error) ToMir

func (t Error) ToMir(code jen.Code) *jen.Statement

func (Error) ToPb

func (t Error) ToPb(code jen.Code) *jen.Statement

type Field

type Field struct {
	// The name of the field.
	Name string

	// The information about the type of the field.
	Type Type

	// The type to which the field belongs.
	Parent *Message

	// The protobuf descriptor of the field.
	// The descriptor can be either protoreflect.FieldDescriptor or protoreflect.OneofDescriptor.
	ProtoDesc protoreflect.Descriptor
}

Field represents a field in a protobuf message. Note: oneofs are not considered as fields in the protobuf data module, but are considered as fields here. The reason for that is that oneofs are mapped to fields in the generated Go code.

func (*Field) FuncParamMirType

func (f *Field) FuncParamMirType() jen.Code

FuncParamMirType returns the field lowercase name followed by its mir type.

func (*Field) FuncParamPbType

func (f *Field) FuncParamPbType() jen.Code

FuncParamPbType returns the field lowercase name followed by its pb type.

func (*Field) LowercaseName

func (f *Field) LowercaseName() string

LowercaseName returns the lowercase name of the field.

type Fields

type Fields []*Field

Fields is a list of fields of a protobuf message.

func (Fields) ByName

func (fs Fields) ByName(name string) *Field

ByName returns the field with the given name (or nil if there is no such field).

func (Fields) FuncParamsIDs

func (fs Fields) FuncParamsIDs() []jen.Code

FuncParamsIDs returns a list of fields lowercase names as identifiers, without the types.

func (Fields) FuncParamsMirTypes

func (fs Fields) FuncParamsMirTypes() []jen.Code

FuncParamsMirTypes returns a list of field lowercase names followed by their mir types.

func (Fields) FuncParamsPbTypes

func (fs Fields) FuncParamsPbTypes() []jen.Code

FuncParamsPbTypes returns a list of field lowercase names followed by their pb types.

type Map added in v0.3.0

type Map struct {
	KeyType   Type
	ValueType Type
}

Map is used to represent map types.

func (Map) MirType added in v0.3.0

func (m Map) MirType() *jen.Statement

func (Map) PbType added in v0.3.0

func (m Map) PbType() *jen.Statement

func (Map) Same added in v0.3.0

func (m Map) Same() bool

func (Map) ToMir added in v0.3.0

func (m Map) ToMir(code jen.Code) *jen.Statement

func (Map) ToPb added in v0.3.0

func (m Map) ToPb(code jen.Code) *jen.Statement

type Message

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

Message contains the information needed to generate code for a protobuf message.

func (*Message) IsMirEvent

func (m *Message) IsMirEvent() bool

func (*Message) IsMirMessage

func (m *Message) IsMirMessage() bool

func (*Message) IsMirStruct

func (m *Message) IsMirStruct() bool

func (*Message) LowercaseName

func (m *Message) LowercaseName() string

LowercaseName returns the name of the message in lowercase.

func (*Message) MirPkgPath

func (m *Message) MirPkgPath() string

func (*Message) MirType

func (m *Message) MirType() *jen.Statement

func (*Message) Name

func (m *Message) Name() string

func (*Message) NewMirType

func (m *Message) NewMirType() *jen.Statement

func (*Message) NewPbType

func (m *Message) NewPbType() *jen.Statement

func (*Message) PbPkgPath

func (m *Message) PbPkgPath() string

func (*Message) PbReflectType

func (m *Message) PbReflectType() reflect.Type

PbReflectType returns the reflect.Type corresponding to the pointer type to the protoc-generated struct for this message.

func (*Message) PbType

func (m *Message) PbType() *jen.Statement

func (*Message) ProtoDesc

func (m *Message) ProtoDesc() protoreflect.MessageDescriptor

ProtoDesc returns the proto descriptor of the message.

func (*Message) Same

func (m *Message) Same() bool

func (*Message) ShouldGenerateMirType

func (m *Message) ShouldGenerateMirType() bool

ShouldGenerateMirType returns true if Mir should generate a struct for the message type.

func (*Message) ToMir

func (m *Message) ToMir(code jen.Code) *jen.Statement

func (*Message) ToPb

func (m *Message) ToPb(code jen.Code) *jen.Statement

type Oneof

type Oneof struct {
	Name    string
	Parent  *Message
	Options []*OneofOption
}

func (*Oneof) MirInterfaceName

func (t *Oneof) MirInterfaceName() string

func (*Oneof) MirMethodName

func (t *Oneof) MirMethodName() string

func (*Oneof) MirType

func (t *Oneof) MirType() *jen.Statement

func (*Oneof) MirWrapperInterface

func (t *Oneof) MirWrapperInterface() *jen.Statement

func (*Oneof) MirWrapperInterfaceName

func (t *Oneof) MirWrapperInterfaceName() string

func (*Oneof) PbExportedInterfaceName

func (t *Oneof) PbExportedInterfaceName() string

func (*Oneof) PbMethodName

func (t *Oneof) PbMethodName() string

func (*Oneof) PbNativeInterfaceName

func (t *Oneof) PbNativeInterfaceName() string

func (*Oneof) PbType

func (t *Oneof) PbType() *jen.Statement

func (*Oneof) Same

func (t *Oneof) Same() bool

func (*Oneof) ToMir

func (t *Oneof) ToMir(code jen.Code) *jen.Statement

func (*Oneof) ToPb

func (t *Oneof) ToPb(code jen.Code) *jen.Statement

type OneofOption

type OneofOption struct {
	PbWrapperReflect reflect.Type
	WrapperName      string
	Field            *Field
}

func (*OneofOption) ConstructMirWrapperType

func (opt *OneofOption) ConstructMirWrapperType(underlying jen.Code) *jen.Statement

func (*OneofOption) MirWrapperStructType

func (opt *OneofOption) MirWrapperStructType() *jen.Statement

func (*OneofOption) MirWrapperType

func (opt *OneofOption) MirWrapperType() *jen.Statement

func (*OneofOption) Name

func (opt *OneofOption) Name() string

Name returns the name of the oneof option. Same as opt.Field.Name.

func (*OneofOption) NewMirWrapperType

func (opt *OneofOption) NewMirWrapperType() *jen.Statement

func (*OneofOption) NewPbWrapperType

func (opt *OneofOption) NewPbWrapperType() *jen.Statement

func (*OneofOption) PbWrapperType

func (opt *OneofOption) PbWrapperType() *jen.Statement

type Parser

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

Parser can be used to parse the protoc-generated types using reflection.

func DefaultParser

func DefaultParser() *Parser

DefaultParser returns a singleton Parser. It must not be accessed concurrently.

func (*Parser) ParseFields

func (p *Parser) ParseFields(m *Message) (fields Fields, err error)

ParseFields parses the fields of a message for which a Mir type is being generated.

func (*Parser) ParseMessage

func (p *Parser) ParseMessage(pbGoStructPtr reflect.Type) (msg *Message, err error)

ParseMessage returns the message corresponding to the given protobuf-generated struct type.

func (*Parser) ParseMessages

func (p *Parser) ParseMessages(pbGoStructPtrTypes []reflect.Type) ([]*Message, error)

func (*Parser) ParseOneofOption

func (p *Parser) ParseOneofOption(message *Message, ptrType reflect.Type) (*OneofOption, error)

type Same

type Same struct {
	Type jen.Code
}

Same is used when the same type is used by protoc-generated code and Mir-generated code.

func (Same) MirType

func (t Same) MirType() *jen.Statement

func (Same) PbType

func (t Same) PbType() *jen.Statement

func (Same) Same

func (t Same) Same() bool

func (Same) ToMir

func (t Same) ToMir(code jen.Code) *jen.Statement

func (Same) ToPb

func (t Same) ToPb(code jen.Code) *jen.Statement

type Slice

type Slice struct {
	Underlying Type
}

Slice is used to represent repeated fields.

func (Slice) MirType

func (s Slice) MirType() *jen.Statement

func (Slice) PbType

func (s Slice) PbType() *jen.Statement

func (Slice) Same

func (s Slice) Same() bool

func (Slice) ToMir

func (s Slice) ToMir(code jen.Code) *jen.Statement

func (Slice) ToPb

func (s Slice) ToPb(code jen.Code) *jen.Statement

type Type

type Type interface {
	// Same returns whether PbType() and MirType() represent the same type.
	Same() bool
	// PbType is the type in the protoc-generated code.
	PbType() *jen.Statement
	// MirType is the type in the Mir-generated code.
	MirType() *jen.Statement
	// ToMir converts an object of the type in protoc representation to its Mir representation.
	ToMir(code jen.Code) *jen.Statement
	// ToPb converts an object of the type in Mir representation to its protoc representation.
	ToPb(code jen.Code) *jen.Statement
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL