Documentation ¶
Index ¶
- func ConvertMap[K, Rk comparable, V, Rv any](tm map[K]V, f func(tk K, tv V) (Rk, Rv)) map[Rk]Rv
- func ConvertSlice[T, R any](ts []T, f func(t T) R) []R
- func ErrorToString(err error) string
- func OutputDir(sourceDir string) string
- func PackageName(sourcePackagePath string) string
- func PackagePath(sourcePackagePath string) string
- func StringToError(s string) error
- type Castable
- type Error
- type Field
- type Fields
- type Map
- type Message
- func (m *Message) IsMirEvent() bool
- func (m *Message) IsMirMessage() bool
- func (m *Message) IsMirStruct() bool
- func (m *Message) LowercaseName() string
- func (m *Message) MirPkgPath() string
- func (m *Message) MirType() *jen.Statement
- func (m *Message) Name() string
- func (m *Message) NewMirType() *jen.Statement
- func (m *Message) NewPbType() *jen.Statement
- func (m *Message) PbPkgPath() string
- func (m *Message) PbReflectType() reflect.Type
- func (m *Message) PbType() *jen.Statement
- func (m *Message) ProtoDesc() protoreflect.MessageDescriptor
- func (m *Message) Same() bool
- func (m *Message) ShouldGenerateMirType() bool
- func (m *Message) ToMir(code jen.Code) *jen.Statement
- func (m *Message) ToPb(code jen.Code) *jen.Statement
- type Oneof
- func (t *Oneof) MirInterfaceName() string
- func (t *Oneof) MirMethodName() string
- func (t *Oneof) MirType() *jen.Statement
- func (t *Oneof) MirWrapperInterface() *jen.Statement
- func (t *Oneof) MirWrapperInterfaceName() string
- func (t *Oneof) PbExportedInterfaceName() string
- func (t *Oneof) PbMethodName() string
- func (t *Oneof) PbNativeInterfaceName() string
- func (t *Oneof) PbType() *jen.Statement
- func (t *Oneof) Same() bool
- func (t *Oneof) ToMir(code jen.Code) *jen.Statement
- func (t *Oneof) ToPb(code jen.Code) *jen.Statement
- type OneofOption
- func (opt *OneofOption) ConstructMirWrapperType(underlying jen.Code) *jen.Statement
- func (opt *OneofOption) MirWrapperStructType() *jen.Statement
- func (opt *OneofOption) MirWrapperType() *jen.Statement
- func (opt *OneofOption) Name() string
- func (opt *OneofOption) NewMirWrapperType() *jen.Statement
- func (opt *OneofOption) NewPbWrapperType() *jen.Statement
- func (opt *OneofOption) PbWrapperType() *jen.Statement
- type Parser
- func (p *Parser) ParseFields(m *Message) (fields Fields, err error)
- func (p *Parser) ParseMessage(pbGoStructPtr reflect.Type) (msg *Message, err error)
- func (p *Parser) ParseMessages(pbGoStructPtrTypes []reflect.Type) ([]*Message, error)
- func (p *Parser) ParseOneofOption(message *Message, ptrType reflect.Type) (*OneofOption, error)
- type Same
- type Slice
- type Type
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 ¶
ErrorToString is used in the generated code to convert an error to a string.
func PackageName ¶
func PackagePath ¶
func StringToError ¶
StringToError is used in the generated code to convert a string to an error.
Types ¶
type Castable ¶
Castable is used when the types used by protoc-generated code and Mir-generated code can be directly cast to one another.
type Error ¶
type Error struct{}
Error represents a string field in a message annotated with [(mir.type) = "error"].
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 ¶
FuncParamMirType returns the field lowercase name followed by its mir type.
func (*Field) FuncParamPbType ¶
FuncParamPbType returns the field lowercase name followed by its pb type.
func (*Field) LowercaseName ¶
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 ¶
ByName returns the field with the given name (or nil if there is no such field).
func (Fields) FuncParamsIDs ¶
FuncParamsIDs returns a list of fields lowercase names as identifiers, without the types.
func (Fields) FuncParamsMirTypes ¶
FuncParamsMirTypes returns a list of field lowercase names followed by their mir types.
func (Fields) FuncParamsPbTypes ¶
FuncParamsPbTypes returns a list of field lowercase names followed by their pb types.
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 (*Message) IsMirMessage ¶
func (*Message) IsMirStruct ¶
func (*Message) LowercaseName ¶
LowercaseName returns the name of the message in lowercase.
func (*Message) MirPkgPath ¶
func (*Message) NewMirType ¶
func (*Message) PbReflectType ¶
PbReflectType returns the reflect.Type corresponding to the pointer type to the protoc-generated struct for this message.
func (*Message) ProtoDesc ¶
func (m *Message) ProtoDesc() protoreflect.MessageDescriptor
ProtoDesc returns the proto descriptor of the message.
func (*Message) ShouldGenerateMirType ¶
ShouldGenerateMirType returns true if Mir should generate a struct for the message type.
type Oneof ¶
type Oneof struct { Name string Parent *Message Options []*OneofOption }
func (*Oneof) MirInterfaceName ¶
func (*Oneof) MirMethodName ¶
func (*Oneof) MirWrapperInterface ¶
func (*Oneof) MirWrapperInterfaceName ¶
func (*Oneof) PbExportedInterfaceName ¶
func (*Oneof) PbMethodName ¶
func (*Oneof) PbNativeInterfaceName ¶
type OneofOption ¶
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 ¶
ParseFields parses the fields of a message for which a Mir type is being generated.
func (*Parser) ParseMessage ¶
ParseMessage returns the message corresponding to the given protobuf-generated struct type.
func (*Parser) ParseMessages ¶
func (*Parser) ParseOneofOption ¶
type Same ¶
Same is used when the same type is used by protoc-generated code and Mir-generated code.
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 }