Documentation
¶
Overview ¶
Package genproto2 generates Go methods that directly encode/decode protobuf3 wire format bytes, without intermediate proto.Message structs. The generated bytes are identical to what amino.MarshalReflect produces.
Index ¶
- func WriteProto3Schema(pkg *amino.Package)
- type NList
- type P3Context
- func (p3c *P3Context) GenerateProto3ListPartial(p3doc *P3Doc, nl NList) (p3msg P3Message)
- func (p3c *P3Context) GenerateProto3MessagePartial(p3doc *P3Doc, rt reflect.Type) (p3msg P3Message)
- func (p3c *P3Context) GenerateProto3SchemaForTypes(pkg *amino.Package, rtz ...reflect.Type) (p3doc P3Doc)
- func (p3c *P3Context) GetAllPackages() (res []*amino.Package)
- func (p3c *P3Context) GetP3ImportPath(p3type P3Type, implicit bool) string
- func (p3c *P3Context) GetPackage(gopkg string) *amino.Package
- func (p3c *P3Context) RegisterPackage(pkg *amino.Package)
- func (p3c *P3Context) ValidateBasic()
- func (p3c *P3Context) WriteProto3SchemaForTypes(filename string, pkg *amino.Package, rtz ...reflect.Type)
- type P3Context2
- func (ctx *P3Context2) GenerateProtobuf3ForTypes(pkg string, rtz ...reflect.Type) (string, error)
- func (ctx *P3Context2) WriteProto3Schema(pkg *amino.Package)
- func (ctx *P3Context2) WriteProtobuf3(pkg *amino.Package)
- func (ctx *P3Context2) WriteProtobuf3ForTypes(filename, pkg string, rtz ...reflect.Type) error
- type P3Doc
- type P3Field
- type P3Import
- type P3Message
- type P3MessageType
- type P3ScalarType
- type P3Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteProto3Schema ¶
Writes in the same directory as the origin package.
Types ¶
type NList ¶
type NList struct {
// Define dimension as followes:
// []struct{} has dimension 1, as well as [][]byte.
// [][]struct{} has dimension 2, as well as [][][]byte.
// When dimension is 2 or greater, we need implicit structs.
// The NestedType is meant to represent these types,
// so Dimensions is usually 2 or greater.
Dimensions int
// UltiElem.ReprType might not be UltiElem.
// Could be []byte.
UltiElem *amino.TypeInfo
// Optional Package, where this nested list was used.
// NOTE: two packages can't (yet?) share nested lists.
Package *amino.Package
// If embedded in a struct.
// Should be sanitized to uniq properly.
FieldOptions amino.FieldOptions
}
This exists as a workaround due to Proto deficiencies, namely how fields can only be repeated, not nestedly-repeated.
func (NList) ElemP3Type ¶
type P3Context ¶
type P3Context struct {
// contains filtered or unexported fields
}
P3Context holds contextual information beyond the P3Doc.
It holds all the package infos needed to derive the full P3doc, including p3 import paths, as well as where to write them, because all of that information is encapsulated in amino.Package.
It also holds a local amino.Codec instance, with package registrations passed through.
func NewP3Context ¶
func NewP3Context() *P3Context
func (*P3Context) GenerateProto3ListPartial ¶
Generate the Proto3 message (partial) schema for an implist list. Imports are added to p3doc.
func (*P3Context) GenerateProto3MessagePartial ¶
Given a codec and some reflection type, generate the Proto3 message (partial) schema. Imports are added to p3doc.
func (*P3Context) GenerateProto3SchemaForTypes ¶
func (p3c *P3Context) GenerateProto3SchemaForTypes(pkg *amino.Package, rtz ...reflect.Type) (p3doc P3Doc)
Given the arguments, create a new P3Doc. pkg is optional.
func (*P3Context) GetAllPackages ¶
Crawls the packages and flattens all dependencies. Includes
func (*P3Context) GetP3ImportPath ¶
TODO: This could live as a method of the package, and only crawl the dependencies of that package. But a method implemented on P3Context should function like this and print an intelligent error. Set implicit to false to assert-that name matches in package. Set implicit to true for implicit structures like nested lists.
func (*P3Context) RegisterPackage ¶
func (*P3Context) ValidateBasic ¶
func (p3c *P3Context) ValidateBasic()
type P3Context2 ¶
type P3Context2 struct {
// contains filtered or unexported fields
}
P3Context2 holds state for generating protobuf3 direct-encoding methods.
func NewP3Context2 ¶
func NewP3Context2(cdc *amino.Codec) *P3Context2
NewP3Context2 creates a generator context with the given codec.
func (*P3Context2) GenerateProtobuf3ForTypes ¶
GenerateProtobuf3ForTypes generates source text for the given types. pkg is the Go package name for the generated file. The returned string is valid Go source.
func (*P3Context2) WriteProto3Schema ¶
func (ctx *P3Context2) WriteProto3Schema(pkg *amino.Package)
WriteProto3Schema generates the .proto schema file for a package, exactly as the package-level WriteProto3Schema does.
func (*P3Context2) WriteProtobuf3 ¶
func (ctx *P3Context2) WriteProtobuf3(pkg *amino.Package)
WriteProtobuf3 generates pb3_gen.go in the package's directory.
func (*P3Context2) WriteProtobuf3ForTypes ¶
func (ctx *P3Context2) WriteProtobuf3ForTypes(filename, pkg string, rtz ...reflect.Type) error
WriteProtobuf3ForTypes generates and writes source to the given filename.
type P3Doc ¶
type P3Doc struct {
PackageName string
GoPackage string // TODO replace with general options
Comment string
Imports []P3Import
Messages []P3Message
}
NOTE: P3Doc and its fields are meant to hold basic AST-like information. No validity checking happens here... it should happen before these values are set. Convenience functions that require much more context like P3Context are OK.
type P3Field ¶
type P3MessageType ¶
type P3MessageType struct {
PackageName string // proto3 package name, optional.
Name string // message name.
OmitPackage bool // if true, PackageName is not printed.
}
var P3AnyType P3MessageType = NewP3MessageType("google.protobuf", "Any")
func NewP3MessageType ¶
func NewP3MessageType(pkg string, name string) P3MessageType
func (P3MessageType) AssertIsP3Type ¶
func (P3MessageType) AssertIsP3Type()
func (P3MessageType) GetFullName ¶
func (p3mt P3MessageType) GetFullName() string
func (P3MessageType) GetName ¶
func (p3mt P3MessageType) GetName() string
func (P3MessageType) GetPackageName ¶
func (p3mt P3MessageType) GetPackageName() string
May be empty if it isn't set (for locally declared messages).
func (*P3MessageType) SetOmitPackage ¶
func (p3mt *P3MessageType) SetOmitPackage()
func (P3MessageType) String ¶
func (p3mt P3MessageType) String() string
type P3ScalarType ¶
type P3ScalarType string
const ( P3ScalarTypeDouble P3ScalarType = "double" P3ScalarTypeFloat P3ScalarType = "float" P3ScalarTypeInt32 P3ScalarType = "int32" P3ScalarTypeInt64 P3ScalarType = "int64" P3ScalarTypeUint32 P3ScalarType = "uint32" P3ScalarTypeUint64 P3ScalarType = "uint64" P3ScalarTypeSint32 P3ScalarType = "sint32" P3ScalarTypeSint64 P3ScalarType = "sint64" P3ScalarTypeFixed32 P3ScalarType = "fixed32" P3ScalarTypeFixed64 P3ScalarType = "fixed64" P3ScalarTypeSfixed32 P3ScalarType = "sfixed32" P3ScalarTypeSfixed64 P3ScalarType = "sfixed64" P3ScalarTypeBool P3ScalarType = "bool" P3ScalarTypeString P3ScalarType = "string" P3ScalarTypeBytes P3ScalarType = "bytes" )
func (P3ScalarType) AssertIsP3Type ¶
func (P3ScalarType) AssertIsP3Type()
func (P3ScalarType) GetFullName ¶
func (st P3ScalarType) GetFullName() string
func (P3ScalarType) GetName ¶
func (st P3ScalarType) GetName() string
func (P3ScalarType) GetPackageName ¶
func (P3ScalarType) GetPackageName() string