genproto

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0, UNKNOWN, UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelCase

func CamelCase(s string) string

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

func MakeProtoFolder(pkg *amino.Package, dirName string)

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

func RunProtoc(pkg *amino.Package, protosDir string)

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

func WriteProto3Schema(pkg *amino.Package)

Writes in the same directory as the origin package.

func WriteProtoBindings

func WriteProtoBindings(pkg *amino.Package)

Writes in the same directory as the origin package. Assumes pb imports in origGoPkgPath+"/pb".

func WriteProtoBindingsForTypes

func WriteProtoBindingsForTypes(filename string, pkg *amino.Package, rtz ...reflect.Type) (err error)

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) Elem

func (nl NList) Elem() NList

func (NList) ElemP3Type

func (nl NList) ElemP3Type() P3Type

func (NList) Key

func (nl NList) Key() string

For uniq'ing.

func (NList) Name

func (nl NList) Name() string

func (NList) P3GoExprString

func (nl NList) P3GoExprString(imports *ast.GenDecl, scope *ast.Scope) string

func (NList) P3Type

func (nl NList) P3Type() P3Type

NOTE: requires nl.Package.

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

func (p3c *P3Context) GenerateProto3ListPartial(p3doc *P3Doc, nl NList) (p3msg P3Message)

Generate the Proto3 message (partial) schema for an implist list. Imports are added to p3doc.

func (*P3Context) GenerateProto3MessagePartial

func (p3c *P3Context) GenerateProto3MessagePartial(p3doc *P3Doc, rt reflect.Type) (p3msg P3Message)

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

func (p3c *P3Context) GetAllPackages() (res []*amino.Package)

Crawls the packages and flattens all dependencies. Includes

func (*P3Context) GetP3ImportPath

func (p3c *P3Context) GetP3ImportPath(p3type P3Type, implicit bool) string

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) GetPackage

func (p3c *P3Context) GetPackage(gopkg string) *amino.Package

func (*P3Context) RegisterPackage

func (p3c *P3Context) RegisterPackage(pkg *amino.Package)

func (*P3Context) ValidateBasic

func (p3c *P3Context) ValidateBasic()

func (*P3Context) WriteProto3SchemaForTypes

func (p3c *P3Context) WriteProto3SchemaForTypes(filename string, pkg *amino.Package, rtz ...reflect.Type)

Convenience.

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.

func (*P3Doc) AddImport

func (doc *P3Doc) AddImport(path string)

func (P3Doc) Print

func (doc P3Doc) Print() string

NOTE: P3Doc imports must be set correctly.

func (P3Doc) PrintCode

func (doc P3Doc) PrintCode(p *press.Press) *press.Press

type P3Field

type P3Field struct {
	Comment  string
	Repeated bool
	Type     P3Type
	Name     string
	JSONName string
	Number   uint32
}

func (P3Field) PrintCode

func (fld P3Field) PrintCode(p *press.Press) *press.Press

type P3Import

type P3Import struct {
	Path string
}

func (P3Import) PrintCode

func (imp P3Import) PrintCode(p *press.Press) *press.Press

type P3Message

type P3Message struct {
	Comment string
	Name    string
	Fields  []P3Field
}

func (P3Message) Print

func (msg P3Message) Print() string

func (P3Message) PrintCode

func (msg P3Message) PrintCode(p *press.Press) *press.Press

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

type P3Type

type P3Type interface {
	AssertIsP3Type()
	GetPackageName() string // proto3 package prefix
	GetName() string        // proto3 name
	GetFullName() string    // proto3 full name
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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