binapigen

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

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

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()
View Source
var Plugins = map[string]*Plugin{}

Functions

func GenerateDefault

func GenerateDefault(gen *Generator)

func ListImportedTypes

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

func RegisterPlugin

func RegisterPlugin(name string, genfn func(*Generator, *File) *GenFile)

func RemoveImportedTypes

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

func Run

func Run(apiDir string, filesToGenerate []string, opts Options, f func(*Generator) error)

func RunPlugin

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

func SortFileObjectsByName

func SortFileObjectsByName(file *vppapi.File)

func SortFilesByImports

func SortFilesByImports(apifiles []*vppapi.File)

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
}

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

type Generator struct {
	Files       []*File
	FilesByName map[string]*File
	FilesByPath map[string]*File
	// contains filtered or unexported fields
}

func New

func New(opts Options, apiFiles []*vppapi.File, filesToGen []string) (*Generator, error)

func (*Generator) Generate

func (g *Generator) Generate() error

func (*Generator) NewGenFile

func (g *Generator) NewGenFile(filename string, importPath GoImportPath) *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

	CRC 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 import paths
	NoVersionInfo    bool   // disables generating version info
	NoSourcePathInfo bool   // disables the 'source: /path' comment
}

type Plugin

type Plugin struct {
	Name         string
	GenerateFile func(*Generator, *File) *GenFile
}

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