vppapi

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package vppapi parses VPP API files without any additional processing.

Index

Constants

View Source
const (
	OptionFormat = "format"

	OptionGitBranch = "branch"
	OptionGitTag    = "tag"
	OptionGitRef    = "ref"
	OptionGitDepth  = "depth"
	OptionGitSubdir = "subdir"

	OptionArchiveCompression = "compression"
	OptionArchiveSubdir      = "subdir"
	OptionArchiveStrip       = "strip"
)
View Source
const (
	VPPVersionEnvVar = "VPP_VERSION"
	VPPDirEnvVar     = "VPP_DIR"
)
View Source
const (
	// DefaultDir is default location of API files.
	DefaultDir = "/usr/share/vpp/api"

	// APIFileExtension is a VPP API file extension suffix
	APIFileExtension = ".api.json"
)
View Source
const (
	OptFileVersion = "version"
)

Variables

This section is empty.

Functions

func FindFiles

func FindFiles(dir string) (files []string, err error)

FindFiles searches for API files in given directory or in a nested directory that is at most one level deeper than dir. This effectively finds all API files under core & plugins directories inside API directory.

func FindFilesRecursive

func FindFilesRecursive(dir string, deep int) (files []string, err error)

FindFilesRecursive searches for API files under dir or in a nested directory that is not nested deeper than deep.

func GetVPPVersionInstalled

func GetVPPVersionInstalled() (string, error)

GetVPPVersionInstalled retrieves VPP version of installed package using dpkg-query.

func GetVPPVersionRepo

func GetVPPVersionRepo(repoDir string) (string, error)

GetVPPVersionRepo retrieves VPP version using script in repo directory.

func ResolveApiDir

func ResolveApiDir(dir string) string

ResolveApiDir checks if parameter dir is a path to directory of local VPP repository and returns path to directory with VPP API JSON files under build-root. It will execute `make json-api-files` in case the folder with VPP API JSON files does not exist yet.

func ResolveVPPVersion

func ResolveVPPVersion(apidir string) string

ResolveVPPVersion resolves version of the VPP for target directory.

Version resolved here can be overriden by setting VPP_VERSION env var.

Types

type AliasType

type AliasType struct {
	Name   string
	Type   string
	Length int `json:",omitempty"`
}

type Counter

type Counter struct {
	Name     string
	Elements []Element `json:",omitempty"`
}

type CounterPaths

type CounterPaths struct {
	Name  string
	Paths []string `json:",omitempty"`
}

type Element

type Element struct {
	Name        string
	Severity    string
	Type        string
	Units       string
	Description string
}

type EnumEntry

type EnumEntry struct {
	Name  string
	Value uint32
}

type EnumType

type EnumType struct {
	Name    string
	Type    string
	Entries []EnumEntry
}

type Field

type Field struct {
	Name     string
	Type     string
	Length   int                    `json:",omitempty"`
	Array    bool                   `json:",omitempty"`
	SizeFrom string                 `json:",omitempty"`
	Meta     map[string]interface{} `json:",omitempty"`
}

type File

type File struct {
	Name string // Name is the name of this API file (without any extension).
	Path string // Path is the location of thi API file relative to API directory.
	CRC  string // CRC is a checksum for this API file.

	// Options is a map of string key-value pairs that provides additional options for this file.
	Options map[string]string `json:",omitempty"`
	// Imports is a list of strings representing the names of API files that are imported by this file.
	Imports []string `json:",omitempty"`

	AliasTypes    []AliasType  `json:",omitempty"`
	EnumTypes     []EnumType   `json:",omitempty"`
	EnumflagTypes []EnumType   `json:",omitempty"`
	StructTypes   []StructType `json:",omitempty"`
	UnionTypes    []UnionType  `json:",omitempty"`

	// Messages is a list of Message objects representing messages used in the API.
	Messages []Message `json:",omitempty"`
	// Service is an object representing the RPC services used in the API.
	// In case there is not any services defined for this File, the Service is nil.
	Service *Service `json:",omitempty"`

	Counters []Counter      `json:",omitempty"`
	Paths    []CounterPaths `json:",omitempty"`
}

File is a single API file and its contents.

func Parse

func Parse() ([]File, error)

Parse parses API files in directory DefaultDir and returns collection of File or an error if any error occurs during parsing.

func ParseDir

func ParseDir(apiDir string) ([]File, error)

ParseDir searches for API files in apiDir, parses the found API files and returns collection of File.

API files must have suffix `.api.json` and must be formatted as JSON.

func ParseFile

func ParseFile(apiFile string) (*File, error)

ParseFile parses API file and returns File or an error if any error occurs during parsing.

func ParseRaw

func ParseRaw(content []byte) (file *File, err error)

ParseRaw parses raw API file content and returns File or an error if any error occurs during parsing.

type InputFormat

type InputFormat string
const (
	FormatNone InputFormat = ""
	FormatDir  InputFormat = "dir"
	FormatGit  InputFormat = "git"
	FormatTar  InputFormat = "tar"
	FormatZip  InputFormat = "zip"
)

type InputRef

type InputRef struct {
	Path    string
	Format  InputFormat
	Options map[string]string
}

InputRef is used to specify reference to VPP API input.

func ParseInputRef

func ParseInputRef(input string) (*InputRef, error)

func (*InputRef) Retrieve

func (input *InputRef) Retrieve() (*VppInput, error)

type Message

type Message struct {
	Name    string
	Fields  []Field
	CRC     string
	Options map[string]string `json:",omitempty"`
	Comment string            `json:",omitempty"`
}

type RPC

type RPC struct {
	Request   string
	Reply     string
	Stream    bool     `json:",omitempty"`
	StreamMsg string   `json:",omitempty"`
	Events    []string `json:",omitempty"`
}

type Schema

type Schema struct {
	// Files is a list of File objects that are part of this scheme.
	Files []File
	// Version is a VPP version of this schema.
	Version string
}

Schema represents a collection of API files for a specific VPP version.

type Service

type Service struct {
	RPCs []RPC `json:",omitempty"`
}

type StructType

type StructType struct {
	Name   string
	Fields []Field
}

type UnionType

type UnionType struct {
	Name   string
	Fields []Field
}

type VppInput

type VppInput struct {
	ApiDirectory string
	Schema       Schema
}

VppInput defines VPP API input source.

func ResolveVppInput

func ResolveVppInput(input string) (*VppInput, error)

ResolveVppInput parses an input string and returns VppInput or an error if a problem occurs durig parsing. The input string consists of path, which can be followed by '#' and one or more options separated by comma. The actual format can be specified explicitely by an option 'format', if that is not the case then the format will be detected from path automatically if possible.

- `path` - `path#option1=val,option2=val`

Available formats:

* Directory: `dir`

  • absolute: `/usr/share/vpp/api`
  • relative: `path/to/apidir`

* Git repository: `git`

* Tarball/Zip Archive (`tar`/`zip`)

Format options:

* Git repository

  • `branch`: name of branch
  • `tag`: specific git tag
  • `ref`: git reference
  • `depth`: git depth
  • `subdir`: subdirectory to use as base directory

* Tarball/ZIP Archive

  • `compression`: compression to use (`gzip`)
  • `subdir`: subdirectory to use as base directory
  • 'strip': strip first N directories, applied before `subdir`

Jump to

Keyboard shortcuts

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