binapigen

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: Apache-2.0 Imports: 23 Imported by: 4

Documentation

Index

Constants

View Source
const (
	U8     = "u8"
	I8     = "i8"
	U16    = "u16"
	I16    = "i16"
	U32    = "u32"
	I32    = "i32"
	U64    = "u64"
	I64    = "i64"
	F64    = "f64"
	BOOL   = "bool"
	STRING = "string"
)
View Source
const (
	OsPkg = GoImportPath("os")
)

library dependencies

Variables

View Source
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,
}
View Source
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",
}
View Source
var Logger = logrus.New()

Functions

func CleanMessageComment added in v0.8.0

func CleanMessageComment(comment string) string

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 GenerateDefault(gen *Generator) error

func GeneratePlugins added in v0.8.0

func GeneratePlugins(genPlugins []string) func(*Generator) error

func ListImportedFiles added in v0.8.0

func ListImportedFiles(files []vppapi.File, file *vppapi.File) []vppapi.File

func ListImportedTypes

func ListImportedTypes(apifiles []vppapi.File, file *vppapi.File) []string

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

func RemoveImportedTypes(apifiles []vppapi.File, apifile *vppapi.File)

RemoveImportedTypes removes imported types from file.

func ResolveImportPath added in v0.8.0

func ResolveImportPath(dir string) (string, error)

ResolveImportPath tries to resolve import path for a directory.

func Run

func Run(vppInput *vppapi.VppInput, opts Options, f func(*Generator) error)

func RunPlugin

func RunPlugin(name string, gen *Generator, file *File) error

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

func SortFileObjectsByName(file *vppapi.File)

SortFileObjectsByName sorts all objects of file by their name.

func SortFilesByImports

func SortFilesByImports(apifiles []vppapi.File)

SortFilesByImports sorts list of files by their imports.

func SortFilesByName added in v0.8.0

func SortFilesByName(apifiles []vppapi.File)

SortFilesByName sorts list of files by their name.

func StripMessageCommentFields added in v0.8.0

func StripMessageCommentFields(comment string, fields ...string) string

StripMessageCommentFields processes a comment string from VPP API message and returns a modified version where a set of fields are omitted.

func WriteContentToFile added in v0.8.0

func WriteContentToFile(outputFile string, content []byte) error

Types

type Alias

type Alias struct {
	vppapi.AliasType

	GoIdent

	TypeBasic  *string
	TypeStruct *Struct
	TypeUnion  *Union
}

type Enum

type Enum struct {
	vppapi.EnumType

	GoIdent

	IsFlag bool
}

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 File struct {
	Desc vppapi.File

	Generate       bool
	FilenamePrefix string
	PackageName    GoPackageName
	GoImportPath   GoImportPath

	Version string
	Imports []string

	Enums   []*Enum
	Unions  []*Union
	Structs []*Struct
	Aliases []*Alias

	Messages []*Message
	Service  *Service
}

func (*File) IsStable added in v0.8.0

func (f *File) IsStable() bool

IsStable return true if file version is >= 1.0.0

type GenFile

type GenFile struct {
	// contains filtered or unexported fields
}

func GenerateAPI

func GenerateAPI(gen *Generator, file *File) *GenFile

func GenerateHTTP

func GenerateHTTP(gen *Generator, file *File) *GenFile

func GenerateRPC

func GenerateRPC(gen *Generator, file *File) *GenFile

func (*GenFile) Content

func (g *GenFile) Content() ([]byte, error)

func (*GenFile) GetFile added in v0.8.0

func (g *GenFile) GetFile() *File

func (*GenFile) GoIdent

func (g *GenFile) GoIdent(ident GoIdent) string

func (*GenFile) Import

func (g *GenFile) Import(importPath GoImportPath)

func (*GenFile) P

func (g *GenFile) P(v ...interface{})

func (*GenFile) Write

func (g *GenFile) Write(p []byte) (n int, err error)

type GenerateAllFn added in v0.8.0

type GenerateAllFn = func(*Generator) []*GenFile

type GenerateFileFn added in v0.8.0

type GenerateFileFn = func(*Generator, *File) *GenFile

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 New

func New(opts Options, input *vppapi.VppInput) (*Generator, error)

func (*Generator) Generate

func (g *Generator) Generate() error

func (*Generator) GetMessageByName added in v0.8.0

func (g *Generator) GetMessageByName(name string) *Message

func (*Generator) GetOpts added in v0.8.0

func (g *Generator) GetOpts() Options

func (*Generator) NewGenFile

func (g *Generator) NewGenFile(filename string, file *File) *GenFile

NewGenFile creates new generated file with

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.

func (GoIdent) String

func (id GoIdent) String() string

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 Message

type Message struct {
	vppapi.Message

	File *File

	CRC     string
	Comment string

	GoIdent

	Fields []*Field
	// contains filtered or unexported fields
}

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.

type RPC

type RPC struct {
	VPP vppapi.RPC

	GoName string

	Service *Service

	MsgRequest *Message
	MsgReply   *Message
	MsgStream  *Message
}

type Service

type Service struct {
	vppapi.Service

	RPCs []*RPC
}

type Struct

type Struct struct {
	vppapi.StructType

	GoIdent

	Fields []*Field
}

type Union

type Union struct {
	vppapi.UnionType

	GoIdent

	Fields []*Field
}

Directories

Path Synopsis
Package vppapi parses VPP API files without any additional processing.
Package vppapi parses VPP API files without any additional processing.

Jump to

Keyboard shortcuts

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