Documentation ¶
Index ¶
- func CamelCase(s string) string
- func GenerateProtoBindingsForTypes(pkg *amino.Package, rtz ...reflect.Type) (file *ast.File, err error)
- func MakeProtoFolder(pkg *amino.Package, dirName string)
- func RunProtoc(pkg *amino.Package, protosDir string)
- func WriteProto3Schema(pkg *amino.Package)
- func WriteProtoBindings(pkg *amino.Package)
- func WriteProtoBindingsForTypes(filename string, pkg *amino.Package, rtz ...reflect.Type) (err error)
- 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 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 CamelCase ¶
From https://github.com/golang/protobuf/blob/master/protoc-gen-go/generator/generator.go#L2648: This is needed to get the P3Go name for a given type.
func GenerateProtoBindingsForTypes ¶
func GenerateProtoBindingsForTypes(pkg *amino.Package, rtz ...reflect.Type) (file *ast.File, err error)
Given genproto generated schema files for Go objects, generate mappers to and from pb messages. The purpose of this is to let Amino use already-optimized probuf logic for serialization.
func MakeProtoFolder ¶
Symlinks .proto files from pkg info to dirname, keeping the go path structure as expected, <dirName>/path/to/gopkg/<gopkgName>.proto. If Pkg.DirName is empty, the package is considered "well known", and the mapping is not made.
func RunProtoc ¶
Uses pkg.P3GoPkgPath to determine where the compiled file goes. If pkg.P3GoPkgPath is a subpath of pkg.GoPkgPath, then it will be written in the relevant subpath in pkg.DirName. `protosDir`: folder where .proto files for all dependencies live.
func WriteProto3Schema ¶
Writes in the same directory as the origin package.
func WriteProtoBindings ¶
Writes in the same directory as the origin package. Assumes pb imports in origGoPkgPath+"/pb".
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 ¶
func (NList) P3GoExprString ¶
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 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