schema

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeStringForSchema

func DecodeStringForSchema(input []byte, s Object) (string, error)

func EncodeStringForSchema

func EncodeStringForSchema(input string, s Object) ([]byte, error)

EncodeStringForSchema takes an input string and a Object, and returns a byte slice representing that string.

func EncodeType

func EncodeType[T SchemaType](v T) ([]byte, error)

EncodeType takes a SchemaType and returns the byte slice representing the data in a format the database expects

Types

type Array

type Array struct {
	Length int
	Type   Type
}

func (Array) IsNumeric

func (a Array) IsNumeric() bool

func (Array) MarshalJSON

func (a Array) MarshalJSON() ([]byte, error)

func (Array) Size

func (a Array) Size() int

func (Array) ToSchema

func (a Array) ToSchema() string

func (Array) Validate

func (a Array) Validate(val []byte) bool

type Composite

type Composite struct {
	Keys   []string
	Values []Object
}

func (Composite) IsNumeric

func (c Composite) IsNumeric() bool

func (Composite) MarshalJSON

func (c Composite) MarshalJSON() ([]byte, error)

func (Composite) ToSchema

func (c Composite) ToSchema() string

func (Composite) Validate

func (c Composite) Validate(val []byte) bool

type Object

type Object interface {
	Validate([]byte) bool
	ToSchema() string
	IsNumeric() bool
}

func Parse

func Parse(s string) (Object, error)

type Parser

type Parser struct {
	Scanner Scanner
}

func (*Parser) Parse

func (p *Parser) Parse() (schema Object, err error)

type Scanner

type Scanner struct {
	Input     string
	Start     int
	Pos       int
	RuneWidth int
	LastWidth int
}

func (*Scanner) Emit

func (s *Scanner) Emit() parse.Token

Emit the next Token found on Scanner.Input

func (*Scanner) MatchKey

func (s *Scanner) MatchKey() int

MatchKey returns the length of the schema key

Grammar:

key = DQUOTE 1*( ALPHA / DIGIT / "_" / "-" ) DQUOTE

func (*Scanner) MatchNumber

func (s *Scanner) MatchNumber() int

func (*Scanner) Rewind

func (s *Scanner) Rewind()

Rewind the last read token

func (*Scanner) SkipToBoundary

func (s *Scanner) SkipToBoundary(boundary boundaryFunc) int

SkipToBoundary returns the number of bytes until the next delimiter. This is useful for skipping over invalid tokens.

type SchemaType

type SchemaType interface {
	[]byte | bool | string | int16 | int32 | int64 | uint16 |
		uint32 | uint64 | float32 | float64
}

type TokenType

type TokenType int
const (
	TOK_INVALID TokenType = iota
	TOK_EOF

	TOK_TYPE
	TOK_COLON
	TOK_COMMA
	TOK_KEY
	TOK_NUMBER

	TOK_BRACKET_O
	TOK_BRACKET_X

	TOK_CURLY_O
	TOK_CURLY_X
)

func (TokenType) ToString

func (t TokenType) ToString() string

type Type

type Type struct {
	Name string
}

func (Type) IsNumeric

func (t Type) IsNumeric() bool

func (Type) MarshalJSON

func (t Type) MarshalJSON() ([]byte, error)

func (Type) Size

func (t Type) Size() int

func (Type) ToSchema

func (t Type) ToSchema() string

func (Type) Validate

func (t Type) Validate(val []byte) bool

type Unknown

type Unknown struct{}

func (Unknown) IsNumeric

func (u Unknown) IsNumeric() bool

func (Unknown) ToSchema

func (u Unknown) ToSchema() string

func (Unknown) Validate

func (u Unknown) Validate(_ []byte) bool

Jump to

Keyboard shortcuts

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