reader

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2023 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

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

func NewReader

func NewReader(dat []byte) *Reader

NewReader creates a new Reader obect with some JSON data.

func (*Reader) Bool

func (r *Reader) Bool() (bool, error)

Bool extracts the next boolean "true" or "false" value from the data and skips all whitespace after it.

func (*Reader) Boolp

func (r *Reader) Boolp() (res *bool, err error)

Bool extracts the next boolean value and returns a pointer variable.

func (*Reader) Bools

func (r *Reader) Bools() (res []bool, err error)

Bools extracts an array of boolean values from the data and skips all whitespace after it. The values must be enclosed in square brackets "[...]" and the values must be separated by commas.

func (*Reader) Bytes

func (r *Reader) Bytes() ([]byte, error)

Bytes returns a byte array containing the next string enclosed by quotes. If the string does not contain escaped characters, it returns data from the source directly, otherwise it allocates a temporary buffer that can be recycled between calls to the function

func (*Reader) CloseArray

func (r *Reader) CloseArray() error

CloseArray consumes a closing square bracket ']' character and skips all whitespaces after it.

func (*Reader) CloseObject

func (r *Reader) CloseObject() error

CloseObject consumes a closing curly brace '}' character and skips all whitespaces after it.

func (*Reader) Float32

func (r *Reader) Float32() (flt float32, err error)

Float32 extracts the next float32 value from the data and skips all whitespace after it.

func (*Reader) Float32p

func (r *Reader) Float32p() (res *float32, err error)

Float32p extracts the next float32 value and returns a pointer variable.

func (*Reader) Float32s

func (r *Reader) Float32s() (res []float32, err error)

Float32s extracts an array of float32 values from the data and skips all whitespace after it. The values must be enclosed in square brackets "[...]" and the values must be separated by commas.

func (*Reader) Float64

func (r *Reader) Float64() (flt float64, err error)

Float64 extracts the next float64 value from the data and skips all whitespace after it.

func (*Reader) Float64p

func (r *Reader) Float64p() (res *float64, err error)

Float64p extracts the next float64 value and returns a pointer variable.

func (*Reader) Float64s

func (r *Reader) Float64s() (res []float64, err error)

Float64s extracts an array of float64 values from the data and skips all whitespace after it. The values must be enclosed in square brackets "[...]" and the values must be separated by commas.

func (*Reader) GetPosition

func (r *Reader) GetPosition() int

GetPosition returns the current cursor position in the reader.

func (*Reader) Int

func (r *Reader) Int() (n int, err error)

Int extracts the next int value from the data and skips all whitespace after it.

func (*Reader) Int16

func (r *Reader) Int16() (n int16, err error)

Int16 extracts the next int16 value from the data and skips all whitespace after it.

func (*Reader) Int16p

func (r *Reader) Int16p() (res *int16, err error)

Int16p extracts the next int16 value and returns a pointer variable.

func (*Reader) Int16s

func (r *Reader) Int16s() (res []int16, err error)

Int16s extracts an array of int16 values from the data and skips all whitespace after it. The values must be enclosed in square brackets "[...]" and the values must be separated by commas.

func (*Reader) Int32

func (r *Reader) Int32() (n int32, err error)

Int32 extracts the next int32 value from the data and skips all whitespace after it.

func (*Reader) Int32p

func (r *Reader) Int32p() (res *int32, err error)

Int32p extracts the next int32 value and returns a pointer variable.

func (*Reader) Int32s

func (r *Reader) Int32s() (res []int32, err error)

Int32s extracts an array of int32 values from the data and skips all whitespace after it. The values must be enclosed in square brackets "[...]" and the values must be separated by commas.

func (*Reader) Int64

func (r *Reader) Int64() (n int64, err error)

Int64 extracts the next int64 value from the data and skips all whitespace after it.

func (*Reader) Int64p

func (r *Reader) Int64p() (res *int64, err error)

Int64p extracts the next int64 value and returns a pointer variable.

func (*Reader) Int64s

func (r *Reader) Int64s() (res []int64, err error)

Int64s extracts an array of int64 values from the data and skips all whitespace after it. The values must be enclosed in square brackets "[...]" and the values must be separated by commas.

func (*Reader) Int8

func (r *Reader) Int8() (n int8, err error)

Int8 extracts the next int8 value from the data and skips all whitespace after it.

func (*Reader) Int8p

func (r *Reader) Int8p() (res *int8, err error)

Int8p extracts the next int8 value and returns a pointer variable.

func (*Reader) Int8s

func (r *Reader) Int8s() (res []int8, err error)

Int8s extracts an array of int8 values from the data and skips all whitespace after it. The values must be enclosed in square brackets "[...]" and the values must be separated by commas.

func (*Reader) Intp

func (r *Reader) Intp() (res *int, err error)

Intp extracts the next int value and returns a pointer variable.

func (*Reader) Ints

func (r *Reader) Ints() (res []int, err error)

Ints extracts an array of int values from the data and skips all whitespace after it. The values must be enclosed in square brackets "[...]" and the values must be separated by commas.

func (*Reader) IsNull

func (r *Reader) IsNull() bool

IsNull directly checks if the next token is a null

func (*Reader) Key

func (r *Reader) Key() ([]byte, error)

Key extracts the next string and checks if it is followed by a colon ':' character. It returns the key if successful.

func (*Reader) Next

func (r *Reader) Next() bool

Next checks if the next character is a comma ',' implying more data exists. If the character is a comma, it skips all whitespaces after it.

func (*Reader) OpenArray

func (r *Reader) OpenArray() error

OpenArray consumes an opening square bracket '[' character and skips all whitespaces after it.

func (*Reader) OpenObject

func (r *Reader) OpenObject() error

OpenObject consumes an opening curly brace '{' character and skips all whitespaces after it.

func (*Reader) Reset

func (r *Reader) Reset()

Reset sets the cursor position of the reader to the beginning of the data.

func (*Reader) SetPosition

func (r *Reader) SetPosition(pos int)

SetPosition sets the cursor position int the reader.

func (*Reader) Skip

func (r *Reader) Skip() (err error)

Skip examines the next token type and skip the value.

func (*Reader) SkipNull

func (r *Reader) SkipNull()

SkipNull moves the cursor forward by 4 places and skips all whitespaces after the token. Only user when it's been confirmed that the next value is null.

func (*Reader) SkipWhiteSpace

func (r *Reader) SkipWhiteSpace()

SkipWhiteSpace consumes any valid whitespace characters. Valid characters are spaces ' ', tabs '\t', new lines '\n' and carriage returns '\r'.

func (*Reader) String

func (r *Reader) String() (string, error)

String extracts the next string value from the data and skips all whitespace after it.

func (*Reader) Stringp

func (r *Reader) Stringp() (res *string, err error)

Stringp extracts the next string value and returns a pointer variable.

func (*Reader) Strings

func (r *Reader) Strings() (res []string, err error)

Ints extracts an array of string values from the data and skips all whitespace after it. The values must be enclosed in square brackets "[...]" and the values must be separated by commas.

func (*Reader) Time

func (r *Reader) Time() (time.Time, error)

Time extracts the next time value from the data and skips all whitespace after it. All standard time formats are processed, but RFC3339Nano is prioritized.

func (*Reader) Timep

func (r *Reader) Timep() (res *time.Time, err error)

Timep extracts the next time value and returns a pointer variable.

func (*Reader) Times

func (r *Reader) Times() (res []time.Time, err error)

Times extracts an array of time values from the data and skips all whitespace after it. The values must be enclosed in square brackets "[...]" and the values must be separated by commas.

func (*Reader) Token

func (r *Reader) Token() TokenKind

Token returns the TokenKind of the next token in the JSON.

func (*Reader) UInt

func (r *Reader) UInt() (n uint, err error)

UInt extracts the next uint value from the data and skips all whitespace after it.

func (*Reader) UInt16

func (r *Reader) UInt16() (n uint16, err error)

UInt16 extracts the next uint16 value from the data and skips all whitespace after it.

func (*Reader) UInt16p

func (r *Reader) UInt16p() (res *uint16, err error)

UInt16p extracts the next uint16 value and returns a pointer variable.

func (*Reader) UInt16s

func (r *Reader) UInt16s() (res []uint16, err error)

UInt16s extracts an array of uint16 values from the data and skips all whitespace after it. The values must be enclosed in square brackets "[...]" and the values must be separated by commas.

func (*Reader) UInt32

func (r *Reader) UInt32() (n uint32, err error)

UInt32 extracts the next uint32 value from the data and skips all whitespace after it.

func (*Reader) UInt32p

func (r *Reader) UInt32p() (res *uint32, err error)

UInt32p extracts the next uint32 value and returns a pointer variable.

func (*Reader) UInt32s

func (r *Reader) UInt32s() (res []uint32, err error)

UInt32s extracts an array of uint32 values from the data and skips all whitespace after it. The values must be enclosed in square brackets "[...]" and the values must be separated by commas.

func (*Reader) UInt64

func (r *Reader) UInt64() (n uint64, err error)

UInt64 extracts the next uint64 value from the data and skips all whitespace after it.

func (*Reader) UInt64p

func (r *Reader) UInt64p() (res *uint64, err error)

UInt64p extracts the next uint64 value and returns a pointer variable.

func (*Reader) UInt64s

func (r *Reader) UInt64s() (res []uint64, err error)

UInt64s extracts an array of uint64 values from the data and skips all whitespace after it. The values must be enclosed in square brackets "[...]" and the values must be separated by commas.

func (*Reader) UInt8

func (r *Reader) UInt8() (n uint8, err error)

UInt8 extracts the next uint8 value from the data and skips all whitespace after it.

func (*Reader) UInt8p

func (r *Reader) UInt8p() (res *uint8, err error)

UInt8p extracts the next uint8 value and returns a pointer variable.

func (*Reader) UInt8s

func (r *Reader) UInt8s() (res []uint8, err error)

UInt8s extracts the next base64 string value enclosed in quotes and returns the value in a byte array. Skips all whitespace after the string.

func (*Reader) UIntp

func (r *Reader) UIntp() (res *uint, err error)

UIntp extracts the next uint value and returns a pointer variable.

func (*Reader) UInts

func (r *Reader) UInts() (res []uint, err error)

UInts extracts an array of uint values from the data and skips all whitespace after it. The values must be enclosed in square brackets "[...]" and the values must be separated by commas.

type TokenKind

type TokenKind int

TokenKind is an enum that represent the type of a JSON token

const (
	InvalidToken TokenKind = iota
	SeparatorToken
	TerminatorToken
	NullToken
	NumberToken
	BooleanToken
	StringToken
	ObjectToken
	ArrayToken
)

TokenKind can be one of these values

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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