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
- func FixedStringLengthBytes(size int) int
- func LayoutAligned(record *Record)
- func LayoutCompact(record *Record)
- type BlockLayout
- type BlockRecord
- type Bytes
- type Enum
- type EnumOption
- type Field
- func Int64Field(name string, offset int32) Field
- func Int64FieldNamed(name, short string, offset int32) Field
- func ListElement(element Field) Field
- func ListField(name string, offset int32, element Field) Field
- func ListFixedElement(max int32, element Field) Field
- func ListFixedField(name string, offset, max int32, element Field) Field
- func StringElement() Field
- func StringField(name string, offset int32, pointerSize int32) Field
- func StringFixedElement(name string, offset, max int32) Field
- func StringFixedField(name string, offset, max int32) Field
- func UInt64Field(name string, offset int32) Field
- type Import
- type JsonLexer
- func (r *JsonLexer) AddError(e error)
- func (r *JsonLexer) AddNonFatalError(e error)
- func (r *JsonLexer) Bool() bool
- func (r *JsonLexer) Bytes() []byte
- func (r *JsonLexer) Consumed()
- func (r *JsonLexer) Delim(c byte)
- func (r *JsonLexer) Error() error
- func (r *JsonLexer) FetchToken()
- func (r *JsonLexer) Float32() float32
- func (r *JsonLexer) Float32Any() float32
- func (r *JsonLexer) Float32Str() float32
- func (r *JsonLexer) Float64() float64
- func (r *JsonLexer) Float64Any() float64
- func (r *JsonLexer) Float64Str() float64
- func (r *JsonLexer) GetNonFatalErrors() []*LexerError
- func (r *JsonLexer) GetPos() int
- func (r *JsonLexer) Int() int
- func (r *JsonLexer) Int16() int16
- func (r *JsonLexer) Int16Any() int16
- func (r *JsonLexer) Int16Str() int16
- func (r *JsonLexer) Int32() int32
- func (r *JsonLexer) Int32Any() int32
- func (r *JsonLexer) Int32Str() int32
- func (r *JsonLexer) Int64() int64
- func (r *JsonLexer) Int64Any() int64
- func (r *JsonLexer) Int64Str() int64
- func (r *JsonLexer) Int8() int8
- func (r *JsonLexer) Int8Any() int8
- func (r *JsonLexer) Int8Str() int8
- func (r *JsonLexer) IntAny() int
- func (r *JsonLexer) IntStr() int
- func (r *JsonLexer) Interface() interface{}
- func (r *JsonLexer) IsDelim(c byte) bool
- func (r *JsonLexer) IsNull() bool
- func (r *JsonLexer) IsStart() bool
- func (r *JsonLexer) JsonNumber() json.Number
- func (r *JsonLexer) Null()
- func (r *JsonLexer) Ok() bool
- func (r *JsonLexer) Raw() []byte
- func (r *JsonLexer) Skip()
- func (r *JsonLexer) SkipRecursive()
- func (r *JsonLexer) String() string
- func (r *JsonLexer) StringIntern() string
- func (r *JsonLexer) Uint() uint
- func (r *JsonLexer) Uint16() uint16
- func (r *JsonLexer) Uint16Any() uint16
- func (r *JsonLexer) Uint16Str() uint16
- func (r *JsonLexer) Uint32() uint32
- func (r *JsonLexer) Uint32Any() uint32
- func (r *JsonLexer) Uint32Str() uint32
- func (r *JsonLexer) Uint64() uint64
- func (r *JsonLexer) Uint64Any() uint64
- func (r *JsonLexer) Uint64Str() uint64
- func (r *JsonLexer) Uint8() uint8
- func (r *JsonLexer) Uint8Any() uint8
- func (r *JsonLexer) Uint8Str() uint8
- func (r *JsonLexer) UintAny() uint
- func (r *JsonLexer) UintStr() uint
- func (r *JsonLexer) UintptrStr() uintptr
- func (r *JsonLexer) UnsafeBytes() []byte
- func (r *JsonLexer) UnsafeFieldName(skipUnescape bool) string
- func (r *JsonLexer) UnsafeString() string
- func (r *JsonLexer) WantColon()
- func (r *JsonLexer) WantComma()
- type JsonWriter
- func (w *JsonWriter) Base64Bytes(data []byte)
- func (w *JsonWriter) Bool(v bool)
- func (w *JsonWriter) Float32(n float32)
- func (w *JsonWriter) Float32Str(n float32)
- func (w *JsonWriter) Float64(n float64)
- func (w *JsonWriter) Float64Str(n float64)
- func (w *JsonWriter) Int(n int)
- func (w *JsonWriter) Int16(n int16)
- func (w *JsonWriter) Int16Str(n int16)
- func (w *JsonWriter) Int32(n int32)
- func (w *JsonWriter) Int32Str(n int32)
- func (w *JsonWriter) Int64(n int64)
- func (w *JsonWriter) Int64Str(n int64)
- func (w *JsonWriter) Int8(n int8)
- func (w *JsonWriter) Int8Str(n int8)
- func (w *JsonWriter) IntStr(n int)
- func (w *JsonWriter) Raw(data []byte, err error)
- func (w *JsonWriter) RawByte(c byte)
- func (w *JsonWriter) RawString(s string)
- func (w *JsonWriter) RawText(data []byte, err error)
- func (w *JsonWriter) Size() int
- func (w *JsonWriter) String(s string)
- func (w *JsonWriter) Uint(n uint)
- func (w *JsonWriter) Uint16(n uint16)
- func (w *JsonWriter) Uint16Str(n uint16)
- func (w *JsonWriter) Uint32(n uint32)
- func (w *JsonWriter) Uint32Str(n uint32)
- func (w *JsonWriter) Uint64(n uint64)
- func (w *JsonWriter) Uint64Str(n uint64)
- func (w *JsonWriter) Uint8(n uint8)
- func (w *JsonWriter) Uint8Str(n uint8)
- func (w *JsonWriter) UintStr(n uint)
- func (w *JsonWriter) UintptrStr(n uintptr)
- type JsonWriterFlags
- type Kind
- type LexerError
- type List
- type LogRecordHeader
- type Map
- type Record
- type RecordLayout
- type Schema
- type SeriesRecordHeader
- type Stream
- type String32
- func (s *String32) Bytes() []byte
- func (s *String32) Cap() int
- func (s *String32) Clone() *String32
- func (s *String32) Len() int
- func (s *String32) MarshalBinary() ([]byte, error)
- func (s *String32) MarshalBinaryTo(b []byte) []byte
- func (s *String32) Mut() *String32Mut
- func (s *String32) ReadFrom(r io.Reader) error
- func (s *String32) String() string
- func (s *String32) StringClone() string
- func (s *String32) UnmarshalBinary(b []byte) error
- func (s *String32) WriteTo(w io.Writer) (n int, err error)
- type String32Mut
- type Union
Constants ¶
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 )
const (
VPointerSize = int32(2)
)
Variables ¶
This section is empty.
Functions ¶
func FixedStringLengthBytes ¶
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 Enum ¶
type Enum struct { Name string `json:"name"` Options []EnumOption `json:"options"` Kind Kind `json:"kind"` }
type EnumOption ¶
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 Int64FieldNamed ¶
func ListElement ¶
func ListFixedElement ¶
func StringElement ¶
func StringElement() Field
func StringFixedElement ¶
func StringFixedField ¶
func UInt64Field ¶
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) AddNonFatalError ¶
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) FetchToken ¶
func (r *JsonLexer) FetchToken()
FetchToken scans the input for the next token.
func (*JsonLexer) Float32Any ¶
func (*JsonLexer) Float32Str ¶
func (*JsonLexer) Float64Any ¶
func (*JsonLexer) Float64Str ¶
func (*JsonLexer) GetNonFatalErrors ¶
func (r *JsonLexer) GetNonFatalErrors() []*LexerError
func (*JsonLexer) Interface ¶
func (r *JsonLexer) Interface() interface{}
Interface fetches an interface{} analogous to the 'encoding/json' package.
func (*JsonLexer) IsDelim ¶
IsDelim returns true if there was no scanning error and next token is the given delimiter.
func (*JsonLexer) IsStart ¶
IsStart returns whether the lexer is positioned at the start of an input string.
func (*JsonLexer) JsonNumber ¶
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 ¶
Ok returns true if no error (including io.EOF) was encountered during scanning.
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) StringIntern ¶
StringIntern reads a string literal, and performs string interning on it.
func (*JsonLexer) UintptrStr ¶
func (*JsonLexer) UnsafeBytes ¶
UnsafeBytes returns the byte slice if the token is a string literal.
func (*JsonLexer) UnsafeFieldName ¶
UnsafeFieldName returns current member name string token
func (*JsonLexer) UnsafeString ¶
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.
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 LexerError ¶
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 LogRecordHeader ¶
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
type RecordLayout ¶
type RecordLayout int32
const ( RecordLayoutCompact RecordLayout = 0 RecordLayoutCacheAligned RecordLayout = 1 )
func (RecordLayout) Layout ¶
func (l RecordLayout) Layout(record *Record)
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 (*String32) MarshalBinary ¶
func (*String32) MarshalBinaryTo ¶
func (*String32) Mut ¶
func (s *String32) Mut() *String32Mut
func (*String32) StringClone ¶
func (*String32) UnmarshalBinary ¶
type String32Mut ¶
type String32Mut struct {
String32
}
func (*String32Mut) Set ¶
func (s *String32Mut) Set(v string)