Documentation
¶
Index ¶
- Constants
- Variables
- func CleanMessageComment(comment string) string
- func GenerateDefault(gen *Generator) error
- func GeneratePlugins(genPlugins []string) func(*Generator) error
- func ListImportedFiles(files []vppapi.File, file *vppapi.File) []vppapi.File
- func ListImportedTypes(apifiles []vppapi.File, file *vppapi.File) []string
- func RegisterPlugin(name string, genfn GenerateFileFn)
- func RemoveImportedTypes(apifiles []vppapi.File, apifile *vppapi.File)
- func ResolveImportPath(dir string) (string, error)
- func Run(vppInput *vppapi.VppInput, opts Options, f func(*Generator) error)
- func RunPlugin(name string, gen *Generator, file *File) error
- func SortFileObjectsByName(file *vppapi.File)
- func SortFilesByImports(apifiles []vppapi.File)
- func SortFilesByName(apifiles []vppapi.File)
- func StripMessageCommentFields(comment string, fields ...string) string
- func WriteContentToFile(outputFile string, content []byte) error
- type Alias
- type Enum
- type Field
- type File
- type GenFile
- type GenerateAllFn
- type GenerateFileFn
- type Generator
- type GoIdent
- type GoImportPath
- type GoPackageName
- type Message
- type Options
- type Plugin
- type RPC
- type Service
- type Struct
- type Union
Constants ¶
const ( U8 = "u8" I8 = "i8" U16 = "u16" I16 = "i16" U32 = "u32" I32 = "i32" U64 = "u64" I64 = "i64" F64 = "f64" BOOL = "bool" STRING = "string" )
const (
OsPkg = GoImportPath("os")
)
library dependencies
Variables ¶
var BaseTypeSizes = map[string]int{ U8: 1, I8: 1, U16: 2, I16: 2, U32: 4, I32: 4, U64: 8, I64: 8, F64: 8, BOOL: 1, STRING: 1, }
var BaseTypesGo = map[string]string{ U8: "uint8", I8: "int8", U16: "uint16", I16: "int16", U32: "uint32", I32: "int32", U64: "uint64", I64: "int64", F64: "float64", BOOL: "bool", STRING: "string", }
var Logger = logrus.New()
Functions ¶
func CleanMessageComment ¶
CleanMessageComment processes a comment string from VPP API message and returns a modified version with the following changes: - trim comment syntax ("/**", "*/") - remove special syntax ("\brief") parts - replace all occurrences of "@param" with a dash ("-").
func GenerateDefault ¶
func GeneratePlugins ¶
func ListImportedFiles ¶
func ListImportedTypes ¶
ListImportedTypes returns list of names for imported types.
func RegisterPlugin ¶
func RegisterPlugin(name string, genfn GenerateFileFn)
RegisterPlugin registers a new plugin with name and generate func. Name must not be empty or already taken.
func RemoveImportedTypes ¶
RemoveImportedTypes removes imported types from file.
func ResolveImportPath ¶
ResolveImportPath tries to resolve import path for a directory.
func RunPlugin ¶
RunPlugin executes plugin with given name, if name is not found it attempts to load plugin from a filesystem, using name as path to the file. The file must be Go binary compiled using "plugin" buildmode and must contain exported func with the signature of GenerateFileFn.
func SortFileObjectsByName ¶
SortFileObjectsByName sorts all objects of file by their name.
func SortFilesByImports ¶
SortFilesByImports sorts list of files by their imports.
func SortFilesByName ¶
SortFilesByName sorts list of files by their name.
func StripMessageCommentFields ¶
StripMessageCommentFields processes a comment string from VPP API message and returns a modified version where a set of fields are omitted.
func WriteContentToFile ¶
Types ¶
type Field ¶
type Field struct {
vppapi.Field
GoName string
// Index defines field index in parent.
Index int
// DefaultValue is a default value of field or
// nil if default value is not defined for field.
DefaultValue interface{}
// Reference to actual type of this field.
//
// For fields with built-in types all of these are nil,
// otherwise only one is set to non-nil value.
TypeEnum *Enum
TypeAlias *Alias
TypeStruct *Struct
TypeUnion *Union
// Parent in which this field is declared.
ParentMessage *Message
ParentStruct *Struct
ParentUnion *Union
// Field reference for fields with variable size.
FieldSizeOf *Field
FieldSizeFrom *Field
}
Field represents a field for message or struct/union types.
type File ¶
type GenFile ¶
type GenFile struct {
// contains filtered or unexported fields
}
func GenerateAPI ¶
func GenerateHTTP ¶
func GenerateRPC ¶
func (*GenFile) Import ¶
func (g *GenFile) Import(importPath GoImportPath)
type GenerateAllFn ¶
type GenerateFileFn ¶
type Generator ¶
type Generator struct {
Files []*File
FilesByName map[string]*File
FilesByPath map[string]*File
// contains filtered or unexported fields
}
Generator processes VPP API files as input, provides API to handle content of generated files.
func (*Generator) GetMessageByName ¶
type GoIdent ¶
type GoIdent struct {
GoName string
GoImportPath GoImportPath
}
GoIdent is a Go identifier, consisting of a name and import path. The name is a single identifier and may not be a dot-qualified selector.
type GoImportPath ¶
type GoImportPath string
GoImportPath is a Go import path for a package.
func (GoImportPath) Ident ¶
func (p GoImportPath) Ident(s string) GoIdent
func (GoImportPath) String ¶
func (p GoImportPath) String() string
type GoPackageName ¶
type GoPackageName string
type Options ¶
type Options struct {
OutputDir string // output directory for generated files
ImportPrefix string // prefix for package import paths
GenerateFiles []string // list of files to generate
NoVersionInfo bool // disables generating version info
NoSourcePathInfo bool // disables the 'source: /path' comment
}
Options is set of input parameters for the Generator.
type Plugin ¶
type Plugin struct {
Name string
GenerateAll GenerateAllFn
GenerateFile GenerateFileFn
External bool
}
Plugin is an extension of the Generator. Plugins can be registered in application with RegisterPlugin or loaded from an external file compiled when calling RunPlugin.