schema

package
v0.0.0-...-958ee23 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MapHeaderSize     = 4
	MapItemHeaderSize = 4
)
View Source
const (
	KindUnknown = Kind(0) // Possibly resolved later
	KindBool    = Kind(1)
	KindByte    = Kind(2)
	KindInt8    = Kind(3)
	KindInt16   = Kind(4)
	KindUInt16  = Kind(5)
	KindInt32   = Kind(6)
	KindUInt32  = Kind(7)
	KindInt64   = Kind(8)
	KindUInt64  = Kind(9)
	KindFloat32 = Kind(10)
	KindFloat64 = Kind(11)
	KindString  = Kind(12)
	KindBytes   = Kind(13)
	KindStruct  = Kind(30) // User-defined structure
	KindEnum    = Kind(31) // User-defined enum
	KindUnion   = Kind(33) // User-defined union
	KindMessage = Kind(40) // User-defined message
	KindList    = Kind(50)
	KindMap     = Kind(60)
	KindPad     = Kind(100) // struct alignment padding
)
View Source
const (
	FileSuffix = ".wap"
)

Variables

View Source
var (
	ErrUnresolved = errors.New("unresolved")
)

Functions

func Align

func Align(t *Type) int

func AlignDown

func AlignDown(n, a uintptr) uintptr

AlignDown rounds n down to a multiple of a. a must be a power of 2.

func AlignUp

func AlignUp(n, a uintptr) uintptr

AlignUp rounds n up to a multiple of a. a must be a power of 2.

func Capitalize

func Capitalize(s string) string

func DivRoundUp

func DivRoundUp(n, a uintptr) uintptr

DivRoundUp returns ceil(n / a).

func FieldAlign

func FieldAlign(size int) int

func IsLetter

func IsLetter(c byte) bool

func IsLower

func IsLower(c byte) bool

func IsNumeral

func IsNumeral(c byte) bool

func IsUpper

func IsUpper(c byte) bool

func IsValidFirst

func IsValidFirst(c rune) bool

func IsValidName

func IsValidName(n string) bool

func IsValidNameCharacter

func IsValidNameCharacter(c rune) bool

func IsWhitespace

func IsWhitespace(c byte) bool

func Join

func Join(left, right string) string

func PackageName

func PackageName(path string) string

func PadEnd

func PadEnd(s string, l int) string

func ParseInt

func ParseInt(kind Kind, v string) (interface{}, error)

func RelativePath

func RelativePath(base, relative string) string

func SimpleName

func SimpleName(str string) string

func StartsWith

func StartsWith(val string, s string) bool

func Uncapitalize

func Uncapitalize(s string) string

Types

type Annotation

type Annotation struct {
	Line  int
	Name  string
	Value interface{}
}

type Builder

type Builder struct {
	*strings.Builder
}

func NewBuilder

func NewBuilder() *Builder

func (Builder) W

func (b Builder) W(v string, params ...interface{})

func (*Builder) WriteLine

func (b *Builder) WriteLine(v string)

type Const

type Const struct {
	Name string
	Type *Type
}

type ConstVal

type ConstVal string

type Dir

type Dir struct {
	Parent *Dir
	Name   string
	Path   string
	Files  map[string]*File
	Dirs   map[string]*Dir
}

type Enum

type Enum struct {
	Name    string
	Type    *Type
	Options []*EnumOption
	// contains filtered or unexported fields
}

func (*Enum) GetOption

func (e *Enum) GetOption(name string) *EnumOption

func (*Enum) OptionMap

func (e *Enum) OptionMap() map[string]*EnumOption

type EnumOption

type EnumOption struct {
	Enum              *Enum
	Name              string
	Comments          []string
	Value             interface{}
	Line              Line
	Deprecated        bool
	DeprecatedMessage string
}

type Expression

type Expression string

type File

type File struct {
	Dir     string
	Name    string
	Path    string
	Package string
	Hash    uint64
	Err     error

	Content   string
	Imports   []*Imports
	Consts    []*Const
	Structs   []*Struct
	Messages  []*Message
	Enums     []*Enum
	Unions    []*Union
	Lists     map[string][]*Type
	Types     map[string]*Type
	ImportMap map[string]*Import
	Strings   map[string][]*Type
	// contains filtered or unexported fields
}

func ParseFile

func ParseFile(path, name string, content []byte) (*File, error)

type Import

type Import struct {
	Imports  *Imports
	Parent   *File
	Path     string
	Name     string
	Alias    string
	File     *File
	Comments []string
	Line     Line
}

type ImportedName

type ImportedName struct {
	Package string
	Name    string
}

type Imports

type Imports struct {
	Line     Line
	Comments []string
	List     []*Import
}

type Kind

type Kind byte

func KindOf

func KindOf(name string) Kind

func (Kind) Size

func (k Kind) Size() int

type Line

type Line struct {
	Number int
	Begin  int
	End    int
}

type List

type List struct {
	Element *Type
}

type Map

type Map struct {
	Key      *Type
	Value    *Type
	ItemSize int
}

type Message

type Message struct {
	Name      string
	Type      *Type
	Fields    []*MessageField
	FieldMap  map[string]*MessageField
	Optionals []*MessageField
	Version   int64
}

type MessageField

type MessageField struct {
	Number    int
	Owner     *Message
	Name      string
	Type      *Type
	Offset    int
	OptOffset int
	OptMask   byte
}

type Nil

type Nil struct{}

type Optional

type Optional struct {
	Index  int
	Offset int
	Mask   byte
}

type Package

type Package struct {
	Name  string
	Files []*File
	Types map[string]*Type
}

type Parser

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

func (*Parser) Parse

func (p *Parser) Parse() (*File, error)

type ProtoBufKind

type ProtoBufKind byte

type Record

type Record struct {
}

Record provides an efficient variable length flat layout. It extends structs with the ability to have variable length strings, lists and other Records. It is similar to FlatBuffer Tables.

type Schema

type Schema struct {
	//Root     *Dir
	Files  map[string]*File
	Errors []error
	// contains filtered or unexported fields
}

func LoadFromFS

func LoadFromFS(dirOrFile string, resolve bool) (*Schema, error)

LoadFromFS loads a schema from the filesystem optionally resolving.

func (*Schema) Resolve

func (pa *Schema) Resolve() error

type Struct

type Struct struct {
	Name      string
	Type      *Type
	Fields    []*StructField
	FieldMap  map[string]*StructField
	Optionals []*StructField
	Version   int64
	Compact   bool
}

Struct represent a fixed sized memory layout similar to how structs memory layout in languages such as Go, Rust, C/C++, etc. Optionally structs can be compact which removes all padding which favors memory size vs CPU cache aligning. For variable memory sizes, use Record.

type StructField

type StructField struct {
	Number    int
	Struct    *Struct
	Name      string
	Short     string
	Type      *Type
	Offset    int
	OptOffset int
	OptMask   byte
}

func (*StructField) IsOptional

func (f *StructField) IsOptional() bool

type Type

type Type struct {
	Line         Line
	File         *File
	Kind         Kind
	Optional     bool
	Resolved     bool
	Size         int
	Len          int // Max length if collection (list or map) or string
	HeaderSize   int
	HeaderOffset int
	Padding      int
	Element      *Type // List element or Map key type
	Value        *Type // Value type if map type
	ItemSize     int
	Import       *Import
	Name         string       // Name of type
	Comments     []string     // Comments
	Description  string       // Description are comments to the right of certain declarations
	Const        *Const       // Const if type represents a single const
	Struct       *Struct      // Struct for 'KindStruct'
	Field        *StructField // Field
	Union        *Union       // Union for 'KindUnion'
	UnionOption  *UnionOption // UnionOption if type represents a single union option
	Enum         *Enum        // Enum for 'KindEnum'
	EnumOption   *EnumOption  // EnumOption if type represents a single enum option
	Init         interface{}  // Initial value
}

func (*Type) Base

func (t *Type) Base() *Type

type Union

type Union struct {
	Name     string
	Comments []string
	Type     *Type
	Options  []*UnionOption
}

type UnionOption

type UnionOption struct {
	Name     string
	Union    *Union
	Type     *Type
	Comments []string
}

type VirtualDir

type VirtualDir struct {
	Name  string        `json:"name"`
	Path  string        `json:"path"`
	Dirs  []VirtualDir  `json:"dirs"`
	Files []VirtualFile `json:"files"`
}

type VirtualFile

type VirtualFile struct {
	Name string `json:"name"`
	Path string `json:"path"`
	Data []byte `json:"data"`
}

Jump to

Keyboard shortcuts

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