runtime2

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: 13 Imported by: 0

Documentation

Overview

Package jlexer contains a JSON lexer implementation.

It is expected that it is mostly used with generated parser code, so the interface is tuned for a parser that knows what kind of data is expected.

Package jwriter contains a JSON writer.

Index

Constants

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)
	KindStringFixed = Kind(13)
	KindBytes       = Kind(14)
	KindFixed       = Kind(15)
	KindTimeRange   = Kind(16)
	KindEnum        = Kind(20) // User-defined enum
	KindRecord      = Kind(30) // User-defined record
	KindStruct      = Kind(31) // User-defined fixed sized record
	KindList        = Kind(40)
	KindMap         = Kind(50)
	KindUnion       = Kind(60)  // User-defined union
	KindPad         = Kind(100) // struct alignment padding
)
View Source
const (
	VPointerSize = int32(2)
)

Variables

This section is empty.

Functions

func FixedStringLengthBytes

func FixedStringLengthBytes(size int) int

func LayoutAligned

func LayoutAligned(record *Record)

func LayoutCompact

func LayoutCompact(record *Record)

Types

type BlockLayout

type BlockLayout int32
const (
	BlockLayoutRow    BlockLayout = 0
	BlockLayoutColumn BlockLayout = 1
)

type BlockRecord

type BlockRecord struct {
}

type Bytes

type Bytes struct {
	Fixed int
}

type Enum

type Enum struct {
	Name    string       `json:"name"`
	Options []EnumOption `json:"options"`
	Kind    Kind         `json:"kind"`
}

type EnumOption

type EnumOption struct {
	Name   string `json:"name"`
	Value  int64  `json:"value"`
	ValueU uint64 `json:"valueU,omitempty"`
}

type Field

type Field struct {
	Name        string   `json:"name"`
	CompactName string   `json:"compact"`
	Comments    []string `json:"comments"`
	Record      *Record  `json:"-"` // oneof
	List        *List    `json:"-"` // oneof
	Map         *Map     `json:"-"` // oneof
	Union       *Union   `json:"-"` // oneof
	Enum        *Enum    `json:"-"` // oneof
	Offset      int32    `json:"offset"`
	Size        int32    `json:"size"`  // Number of bytes
	Align       int32    `json:"align"` // Number of bytes
	Number      uint16   `json:"number"`
	Kind        Kind     `json:"kind"`
	Optional    bool     `json:"optional"`
	Pointer     bool     `json:"pointer"`
}

Field represents a field on a Record, List Element, or Map Key/Value

func Int64Field

func Int64Field(name string, offset int32) Field

func Int64FieldNamed

func Int64FieldNamed(name, short string, offset int32) Field

func ListElement

func ListElement(element Field) Field

func ListField

func ListField(name string, offset int32, element Field) Field

func ListFixedElement

func ListFixedElement(max int32, element Field) Field

func ListFixedField

func ListFixedField(name string, offset, max int32, element Field) Field

func StringElement

func StringElement() Field

func StringField

func StringField(name string, offset int32, pointerSize int32) Field

func StringFixedElement

func StringFixedElement(name string, offset, max int32) Field

func StringFixedField

func StringFixedField(name string, offset, max int32) Field

func UInt64Field

func UInt64Field(name string, offset int32) Field

func (*Field) IsPointer

func (f *Field) IsPointer() bool

type Import

type Import struct {
	FQN  string `json:"fqn"`
	Name string `json:"name"`
}

type JsonLexer

type JsonLexer struct {
	Data []byte // Input data given to the lexer.

	UseMultipleErrors bool // If we want to use multiple errors.
	// contains filtered or unexported fields
}

JsonLexer is a JSON lexer: it iterates over JSON tokens in a byte slice.

func (*JsonLexer) AddError

func (r *JsonLexer) AddError(e error)

func (*JsonLexer) AddNonFatalError

func (r *JsonLexer) AddNonFatalError(e error)

func (*JsonLexer) Bool

func (r *JsonLexer) Bool() bool

Bool reads a true or false boolean keyword.

func (*JsonLexer) Bytes

func (r *JsonLexer) Bytes() []byte

Bytes reads a string literal and base64 decodes it into a byte slice.

func (*JsonLexer) Consumed

func (r *JsonLexer) Consumed()

Consumed reads all remaining bytes from the input, publishing an error if there is anything but whitespace remaining.

func (*JsonLexer) Delim

func (r *JsonLexer) Delim(c byte)

Delim consumes a token and verifies that it is the given delimiter.

func (*JsonLexer) Error

func (r *JsonLexer) Error() error

func (*JsonLexer) FetchToken

func (r *JsonLexer) FetchToken()

FetchToken scans the input for the next token.

func (*JsonLexer) Float32

func (r *JsonLexer) Float32() float32

func (*JsonLexer) Float32Any

func (r *JsonLexer) Float32Any() float32

func (*JsonLexer) Float32Str

func (r *JsonLexer) Float32Str() float32

func (*JsonLexer) Float64

func (r *JsonLexer) Float64() float64

func (*JsonLexer) Float64Any

func (r *JsonLexer) Float64Any() float64

func (*JsonLexer) Float64Str

func (r *JsonLexer) Float64Str() float64

func (*JsonLexer) GetNonFatalErrors

func (r *JsonLexer) GetNonFatalErrors() []*LexerError

func (*JsonLexer) GetPos

func (r *JsonLexer) GetPos() int

func (*JsonLexer) Int

func (r *JsonLexer) Int() int

func (*JsonLexer) Int16

func (r *JsonLexer) Int16() int16

func (*JsonLexer) Int16Any

func (r *JsonLexer) Int16Any() int16

func (*JsonLexer) Int16Str

func (r *JsonLexer) Int16Str() int16

func (*JsonLexer) Int32

func (r *JsonLexer) Int32() int32

func (*JsonLexer) Int32Any

func (r *JsonLexer) Int32Any() int32

func (*JsonLexer) Int32Str

func (r *JsonLexer) Int32Str() int32

func (*JsonLexer) Int64

func (r *JsonLexer) Int64() int64

func (*JsonLexer) Int64Any

func (r *JsonLexer) Int64Any() int64

func (*JsonLexer) Int64Str

func (r *JsonLexer) Int64Str() int64

func (*JsonLexer) Int8

func (r *JsonLexer) Int8() int8

func (*JsonLexer) Int8Any

func (r *JsonLexer) Int8Any() int8

func (*JsonLexer) Int8Str

func (r *JsonLexer) Int8Str() int8

func (*JsonLexer) IntAny

func (r *JsonLexer) IntAny() int

func (*JsonLexer) IntStr

func (r *JsonLexer) IntStr() int

func (*JsonLexer) Interface

func (r *JsonLexer) Interface() interface{}

Interface fetches an interface{} analogous to the 'encoding/json' package.

func (*JsonLexer) IsDelim

func (r *JsonLexer) IsDelim(c byte) bool

IsDelim returns true if there was no scanning error and next token is the given delimiter.

func (*JsonLexer) IsNull

func (r *JsonLexer) IsNull() bool

IsNull returns true if the next token is a null keyword.

func (*JsonLexer) IsStart

func (r *JsonLexer) IsStart() bool

IsStart returns whether the lexer is positioned at the start of an input string.

func (*JsonLexer) JsonNumber

func (r *JsonLexer) JsonNumber() json.Number

JsonNumber fetches and json.Number from 'encoding/json' package. Both int, float or string, contains them are valid values

func (*JsonLexer) Null

func (r *JsonLexer) Null()

Null verifies that the next token is null and consumes it.

func (*JsonLexer) Ok

func (r *JsonLexer) Ok() bool

Ok returns true if no error (including io.EOF) was encountered during scanning.

func (*JsonLexer) Raw

func (r *JsonLexer) Raw() []byte

Raw fetches the next item recursively as a data slice

func (*JsonLexer) Skip

func (r *JsonLexer) Skip()

Skip skips a single token.

func (*JsonLexer) SkipRecursive

func (r *JsonLexer) SkipRecursive()

SkipRecursive skips next array or object completely, or just skips a single token if not an array/object.

Note: no syntax validation is performed on the skipped data.

func (*JsonLexer) String

func (r *JsonLexer) String() string

String reads a string literal.

func (*JsonLexer) StringIntern

func (r *JsonLexer) StringIntern() string

StringIntern reads a string literal, and performs string interning on it.

func (*JsonLexer) Uint

func (r *JsonLexer) Uint() uint

func (*JsonLexer) Uint16

func (r *JsonLexer) Uint16() uint16

func (*JsonLexer) Uint16Any

func (r *JsonLexer) Uint16Any() uint16

func (*JsonLexer) Uint16Str

func (r *JsonLexer) Uint16Str() uint16

func (*JsonLexer) Uint32

func (r *JsonLexer) Uint32() uint32

func (*JsonLexer) Uint32Any

func (r *JsonLexer) Uint32Any() uint32

func (*JsonLexer) Uint32Str

func (r *JsonLexer) Uint32Str() uint32

func (*JsonLexer) Uint64

func (r *JsonLexer) Uint64() uint64

func (*JsonLexer) Uint64Any

func (r *JsonLexer) Uint64Any() uint64

func (*JsonLexer) Uint64Str

func (r *JsonLexer) Uint64Str() uint64

func (*JsonLexer) Uint8

func (r *JsonLexer) Uint8() uint8

func (*JsonLexer) Uint8Any

func (r *JsonLexer) Uint8Any() uint8

func (*JsonLexer) Uint8Str

func (r *JsonLexer) Uint8Str() uint8

func (*JsonLexer) UintAny

func (r *JsonLexer) UintAny() uint

func (*JsonLexer) UintStr

func (r *JsonLexer) UintStr() uint

func (*JsonLexer) UintptrStr

func (r *JsonLexer) UintptrStr() uintptr

func (*JsonLexer) UnsafeBytes

func (r *JsonLexer) UnsafeBytes() []byte

UnsafeBytes returns the byte slice if the token is a string literal.

func (*JsonLexer) UnsafeFieldName

func (r *JsonLexer) UnsafeFieldName(skipUnescape bool) string

UnsafeFieldName returns current member name string token

func (*JsonLexer) UnsafeString

func (r *JsonLexer) UnsafeString() string

UnsafeString returns the string value if the token is a string literal.

Warning: returned string may point to the input buffer, so the string should not outlive the input buffer. Intended pattern of usage is as an argument to a switch statement.

func (*JsonLexer) WantColon

func (r *JsonLexer) WantColon()

WantColon requires a colon to be present before fetching next token.

func (*JsonLexer) WantComma

func (r *JsonLexer) WantComma()

WantComma requires a comma to be present before fetching next token.

type JsonWriter

type JsonWriter struct {
	W            nogc.Bytes
	Flags        JsonWriterFlags
	Error        error
	NoEscapeHTML bool
}

JsonWriter is a JSON writer.

func (*JsonWriter) Base64Bytes

func (w *JsonWriter) Base64Bytes(data []byte)

Base64Bytes appends data to the buffer after base64 encoding it

func (*JsonWriter) Bool

func (w *JsonWriter) Bool(v bool)

func (*JsonWriter) Float32

func (w *JsonWriter) Float32(n float32)

func (*JsonWriter) Float32Str

func (w *JsonWriter) Float32Str(n float32)

func (*JsonWriter) Float64

func (w *JsonWriter) Float64(n float64)

func (*JsonWriter) Float64Str

func (w *JsonWriter) Float64Str(n float64)

func (*JsonWriter) Int

func (w *JsonWriter) Int(n int)

func (*JsonWriter) Int16

func (w *JsonWriter) Int16(n int16)

func (*JsonWriter) Int16Str

func (w *JsonWriter) Int16Str(n int16)

func (*JsonWriter) Int32

func (w *JsonWriter) Int32(n int32)

func (*JsonWriter) Int32Str

func (w *JsonWriter) Int32Str(n int32)

func (*JsonWriter) Int64

func (w *JsonWriter) Int64(n int64)

func (*JsonWriter) Int64Str

func (w *JsonWriter) Int64Str(n int64)

func (*JsonWriter) Int8

func (w *JsonWriter) Int8(n int8)

func (*JsonWriter) Int8Str

func (w *JsonWriter) Int8Str(n int8)

func (*JsonWriter) IntStr

func (w *JsonWriter) IntStr(n int)

func (*JsonWriter) Raw

func (w *JsonWriter) Raw(data []byte, err error)

Raw appends raw binary data to the buffer or sets the error if it is given. Useful for calling with results of MarshalJSON-like functions.

func (*JsonWriter) RawByte

func (w *JsonWriter) RawByte(c byte)

RawByte appends raw binary data to the buffer.

func (*JsonWriter) RawString

func (w *JsonWriter) RawString(s string)

RawString appends raw binary data to the buffer.

func (*JsonWriter) RawText

func (w *JsonWriter) RawText(data []byte, err error)

RawText encloses raw binary data in quotes and appends in to the buffer. Useful for calling with results of MarshalText-like functions.

func (*JsonWriter) Size

func (w *JsonWriter) Size() int

Size returns the size of the data that was written out.

func (*JsonWriter) String

func (w *JsonWriter) String(s string)

func (*JsonWriter) Uint

func (w *JsonWriter) Uint(n uint)

func (*JsonWriter) Uint16

func (w *JsonWriter) Uint16(n uint16)

func (*JsonWriter) Uint16Str

func (w *JsonWriter) Uint16Str(n uint16)

func (*JsonWriter) Uint32

func (w *JsonWriter) Uint32(n uint32)

func (*JsonWriter) Uint32Str

func (w *JsonWriter) Uint32Str(n uint32)

func (*JsonWriter) Uint64

func (w *JsonWriter) Uint64(n uint64)

func (*JsonWriter) Uint64Str

func (w *JsonWriter) Uint64Str(n uint64)

func (*JsonWriter) Uint8

func (w *JsonWriter) Uint8(n uint8)

func (*JsonWriter) Uint8Str

func (w *JsonWriter) Uint8Str(n uint8)

func (*JsonWriter) UintStr

func (w *JsonWriter) UintStr(n uint)

func (*JsonWriter) UintptrStr

func (w *JsonWriter) UintptrStr(n uintptr)

type JsonWriterFlags

type JsonWriterFlags int

JsonWriterFlags describe various encoding options. The behavior may be actually implemented in the encoder, but JsonWriterFlags field in JsonWriter is used to set and pass them around.

const (
	NilMapAsEmpty   JsonWriterFlags = 1 << iota // Encode nil map as '{}' rather than 'null'.
	NilSliceAsEmpty                             // Encode nil slice as '[]' rather than 'null'.
)

type Kind

type Kind byte

type LexerError

type LexerError struct {
	Reason string
	Offset int
	Data   string
}

LexerError implements the error interface and represents all possible errors that can be generated during parsing the JSON data.

func (*LexerError) Error

func (l *LexerError) Error() string

type List

type List struct {
	Element Field `json:"element"`
	Fixed   int   `json:"fixed"`
}

List represents an Array like structure. Header: | LEN 2 bytes | [LEN]Element

type LogRecordHeader

type LogRecordHeader interface {
	RecordID() int64

	Timestamp() int64

	Size() int
}

type Map

type Map struct {
	Key     Field        `json:"key"`
	Value   Field        `json:"value"`
	Default nogc.Pointer `json:"-"`
}

Map represents a HashMap data structure using a robin-hood algorithm Header: | LEN 2 bytes | SIZE 2 bytes | List<MapEntry> Item: | KEY | VALUE | Distance (2 bytes)

type Record

type Record struct {
	Name         string            `json:"name"`
	Comments     []string          `json:"comments"`
	Fields       []Field           `json:"fields"`
	Header       []int             `json:"header,omitempty"`
	HeaderFields []*Field          `json:"-"`
	FieldsMap    map[string]*Field `json:"-"`
	Version      int64             `json:"version"`
	Size         int32             `json:"size"`
	Layout       RecordLayout      `json:"layout,omitempty"`
	Flex         bool              `json:"flex"` // Does Record have any variable fields?
}

func TimeRangeHeaderRecord

func TimeRangeHeaderRecord() Record

func TimeRangeRecord

func TimeRangeRecord() Record

func (*Record) Field

func (r *Record) Field(name string) *Field

func (*Record) FieldAt

func (r *Record) FieldAt(index int) *Field

func (*Record) IsFlex

func (r *Record) IsFlex() bool

func (*Record) Validate

func (r *Record) Validate()

type RecordLayout

type RecordLayout int32
const (
	RecordLayoutCompact      RecordLayout = 0
	RecordLayoutCacheAligned RecordLayout = 1
)

func (RecordLayout) Layout

func (l RecordLayout) Layout(record *Record)

type Schema

type Schema struct {
	FQN        string             `json:"fqn"`
	Name       string             `json:"name"`
	Records    []Record           `json:"records"`
	RecordsMap map[string]*Record `json:"-"`
	Lists      []List             `json:"lists"`
	Streams    []Stream           `json:"streams"`
}

type SeriesRecordHeader

type SeriesRecordHeader interface {
	LogRecordHeader

	Start() int64

	End() int64
}

type Stream

type Stream struct {
	Name       string      `json:"name"`
	RecordName string      `json:"record"`
	Record     *Record     `json:"-"`
	Layout     BlockLayout `json:"layout"` // Row (Arrays of Structs) or Column (Struct of Arrays *fixed only)
}

Stream is a special type for Streaming. It's a list of Records that fits inside 1KB, 2KB, 4KB, 8KB, 16KB, 32KB or 64KB blocks.

type String32

type String32 [32]byte

func NewString32

func NewString32(s string) *String32

func (*String32) Bytes

func (s *String32) Bytes() []byte

func (*String32) Cap

func (s *String32) Cap() int

func (*String32) Clone

func (s *String32) Clone() *String32

func (*String32) Len

func (s *String32) Len() int

func (*String32) MarshalBinary

func (s *String32) MarshalBinary() ([]byte, error)

func (*String32) MarshalBinaryTo

func (s *String32) MarshalBinaryTo(b []byte) []byte

func (*String32) Mut

func (s *String32) Mut() *String32Mut

func (*String32) ReadFrom

func (s *String32) ReadFrom(r io.Reader) error

func (*String32) String

func (s *String32) String() string

func (*String32) StringClone

func (s *String32) StringClone() string

func (*String32) UnmarshalBinary

func (s *String32) UnmarshalBinary(b []byte) error

func (*String32) WriteTo

func (s *String32) WriteTo(w io.Writer) (n int, err error)

type String32Mut

type String32Mut struct {
	String32
}

func (*String32Mut) Set

func (s *String32Mut) Set(v string)

type Union

type Union struct {
	Options []Field
}

Union represents a C-like union or a protobuf oneOf

Directories

Path Synopsis
Package intern interns strings.
Package intern interns strings.
internal

Jump to

Keyboard shortcuts

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