go_protobuf

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2022 License: MulanPSL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TmplDefineST = &generator.TemplateHeader{
	Name:     "go_protobuf_define_st",
	Filepath: "go_protobuf_define_st.tmpl",

	BuiltinTemplateText: `
func (st *{{.Name}}) Name() string {
	return "{{.Name}}"
}
func (st *{{.Name}}) NewST() DefineST {
	return New{{.Name}}()
}
func (st *{{.Name}}) Encode() ([]byte, error) {
	return pb_proto.Marshal(st)
}
func (st *{{.Name}}) Decode(bs []byte) error {
	return pb_proto.Unmarshal(bs, st)
}

{{.DocComment}}
func New{{.Name}}() *{{.Name}} {
	return &{{.Name}}{ {{range .Fields}}{{if (ne .ShouldInitCustomType "")}}
	    {{.Name}}: New{{.ShouldInitCustomType}}(),
{{end}}{{end}}
	}
}
`,
}
View Source
var TmplMessage = &generator.TemplateHeader{
	Name:     "go_protobuf_message",
	Filepath: "go_protobuf_message.tmpl",

	BuiltinTemplateText: `func (st *{{.Name}}) ProtoID() uint32 {
	return {{.ProtoIDName}}
}
func (st *{{.Name}}) New() Message {
	return New{{.Name}}()
}
`,
}
View Source
var TmplProtoFile = &generator.TemplateHeader{
	Name:     "go_protobuf_proto_file",
	Filepath: "go_protobuf_proto_file.tmpl",

	BuiltinTemplateText: `package {{.PackageName}}

import (
	pb_proto "google.golang.org/protobuf/proto"{{if (len .Import | ne 0)}}{{range .Import}}
	{{.}}{{end}}{{end}}
)

func init() { {{range .DefineSTName}}
RegMessageDef(New{{.}}()){{end}}
}
`,
}

Functions

func GenCodeForDefineST

func GenCodeForDefineST(pSet *generator.PrototypeSet, df *generator.DefineST) (string, error)

func GenCodeForMessage

func GenCodeForMessage(pSet *generator.PrototypeSet, dm *generator.Message) (string, error)

func GenFileForMessage

func GenFileForMessage(pSet *generator.PrototypeSet, origFn string) error

func GenFileForSet

func GenFileForSet(pSet *generator.PrototypeSet) error

Types

type Generator

type Generator struct {
}

func (*Generator) Generate

func (*Generator) Lang

func (g *Generator) Lang() string

func (*Generator) NewConfig

func (g *Generator) NewConfig() generator.GeneratorConfig

func (*Generator) Proto

func (g *Generator) Proto() string

type GeneratorConfig

type GeneratorConfig struct {
	Dir         string `json:"dir,omitempty"`
	PackageName string `json:"package_name,omitempty"`

	ProtoDir string `json:"proto_dir,omitempty"`

	MessageFilename string `json:"message_filename,omitempty"`
	ConstFilename   string `json:"const_filename,omitempty"`

	Plugins []string `json:"plugins,omitempty"`
}

type TmplDefineSTData added in v0.2.0

type TmplDefineSTData struct {
	Name       string
	DocComment string
	Fields     []*TmplDefineSTDataField

	Plugins map[string]interface{}
}

type TmplDefineSTDataField added in v0.2.0

type TmplDefineSTDataField struct {
	Name string

	ShouldInitCustomType string

	Plugins map[string]interface{}
}

type TmplMessageData added in v0.2.0

type TmplMessageData struct {
	Name        string
	ProtoIDName string

	Plugins map[string]interface{}
}

type TmplProtoFileData added in v0.2.0

type TmplProtoFileData struct {
	Import      []string
	PackageName string

	DefineSTName []string

	Plugins map[string]interface{}
}

Jump to

Keyboard shortcuts

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