go_json

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_json_define_st",
	Filepath: "go_json_define_st.tmpl",

	BuiltinTemplateText: `
{{.DocComment}}
type {{.Name}} struct { {{range .Fields}}{{if (ne .DocComment "")}}
    {{.DocComment}}
{{end}}    {{.Name}} {{.TypeStr}}` + "{{if (ne .Tag \"\")}} `json:\"{{.Tag}}\"`{{end}}" + `{{if (ne .LineComment "")}} {{.LineComment}}{{end}}
{{end}} }
func (st *{{.Name}}) Name() string {
	return "{{.Name}}"
}
func (st *{{.Name}}) NewST() DefineST {
	return New{{.Name}}()
}
func (st *{{.Name}}) Encode() ([]byte, error) {
	return json.Marshal(st)
}
func (st *{{.Name}}) Decode(bs []byte) error {
	return json.Unmarshal(bs, st)
}
func (st *{{.Name}}) String() string {
	bs, _ := json.Marshal(st)
	return string(bs)
}
func New{{.Name}}() *{{.Name}} {
	return &{{.Name}}{ {{range .Fields}}{{if (ne .ShouldInitCustomType "")}}
	    {{.Name}}: New{{.ShouldInitCustomType}}(),
{{end}}{{end}}
	}
}
`,
}
View Source
var TmplMessage = &generator.TemplateHeader{
	Name:     "go_json_message",
	Filepath: "go_json_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_json_proto_file",
	Filepath: "go_json_proto_file.tmpl",

	BuiltinTemplateText: `package {{.PackageName}}

import (
	"encoding/json"{{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"`

	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
	TypeStr     string
	DocComment  string
	LineComment string

	Tag 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{}
}

Directories

Path Synopsis
plugins

Jump to

Keyboard shortcuts

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