Documentation
¶
Index ¶
- Variables
- func JStructParseFn(rd io.Reader, v JStructOps) (e error)
- func JStructSerializeFn(v JStructOps, wr io.Writer) (e error)
- func MarshalJSONFn(v JStructOps) ([]byte, error)
- func ParsePrimitiveValue(bt byte, rd *bufio.Reader, v JStructOps) (e error)
- func UnmarshalJSONFn(b []byte, v JStructOps) error
- type ArrayOps
- type GeneralOps
- type InvalidJsonError
- type InvalidJsonPtrError
- type InvalidJsonTokenPtrError
- type JStructConvertibleOps
- type JStructOps
- type JStructScanner
- type JStructScannerImpl
- func (j *JStructScannerImpl) Buffer() []byte
- func (j *JStructScannerImpl) Bytes() []byte
- func (j *JStructScannerImpl) Current() byte
- func (j *JStructScannerImpl) FillBuffFrom(idx int) (int, error)
- func (j *JStructScannerImpl) Index() int
- func (j *JStructScannerImpl) Next() error
- func (j *JStructScannerImpl) Scan(n int) error
- func (j *JStructScannerImpl) Window() (int, int)
- type JStructTokenizer
- type JStructTokenizerImpl
- func (t *JStructTokenizerImpl) Kind() TokenizerKind
- func (t *JStructTokenizerImpl) Level() TokenizerLevel
- func (t *JStructTokenizerImpl) Next() error
- func (t *JStructTokenizerImpl) PopLevel()
- func (t *JStructTokenizerImpl) PushLevel(l TokenizerLevel)
- func (t *JStructTokenizerImpl) ReadExponentPart(firstIdx int) error
- func (t *JStructTokenizerImpl) ReadFalse() error
- func (t *JStructTokenizerImpl) ReadFractionPart(firstIdx int) error
- func (t *JStructTokenizerImpl) ReadNull() error
- func (t *JStructTokenizerImpl) ReadNumber(hasMinus bool) error
- func (t *JStructTokenizerImpl) ReadString() error
- func (t *JStructTokenizerImpl) ReadStringTime() error
- func (t *JStructTokenizerImpl) ReadTrue() error
- func (t *JStructTokenizerImpl) Value() []byte
- type JsonStruct
- func (s *JsonStruct) AsArray()
- func (s *JsonStruct) AsObject()
- func (s *JsonStruct) Bool() bool
- func (s *JsonStruct) Float() float64
- func (s *JsonStruct) GetIndex(i int) JStructOps
- func (s *JsonStruct) GetKey(key string) JStructOps
- func (s *JsonStruct) HasKey(key string) bool
- func (s *JsonStruct) Int() int64
- func (s *JsonStruct) IsArray() bool
- func (s *JsonStruct) IsBool() bool
- func (s *JsonStruct) IsFloat() bool
- func (s *JsonStruct) IsInt() bool
- func (s *JsonStruct) IsNull() bool
- func (s *JsonStruct) IsNumber() bool
- func (s *JsonStruct) IsObject() bool
- func (s *JsonStruct) IsString() bool
- func (s *JsonStruct) IsTime() bool
- func (s *JsonStruct) IsUint() bool
- func (s *JsonStruct) Keys() []string
- func (s *JsonStruct) MarshalJSON() ([]byte, error)
- func (s *JsonStruct) Pop() JStructOps
- func (s *JsonStruct) Push(v interface{}) error
- func (s *JsonStruct) RemoveKey(key string) JStructOps
- func (s *JsonStruct) SetBool(v bool)
- func (s *JsonStruct) SetFloat(v float64)
- func (s *JsonStruct) SetIndex(i int, v interface{}) error
- func (s *JsonStruct) SetInt(v int64)
- func (s *JsonStruct) SetKey(key string, v interface{}) error
- func (s *JsonStruct) SetNull()
- func (s *JsonStruct) SetString(v string)
- func (s *JsonStruct) SetTime(v time.Time)
- func (s *JsonStruct) SetUint(v uint64)
- func (s *JsonStruct) Shift() JStructOps
- func (s *JsonStruct) Size() int
- func (s *JsonStruct) String() string
- func (s *JsonStruct) Time() time.Time
- func (s *JsonStruct) Type() Type
- func (s *JsonStruct) Uint() uint64
- func (s *JsonStruct) UnmarshalJSON(bytes []byte) error
- func (s *JsonStruct) Value() interface{}
- type ObjectOps
- type PrimitiveOps
- type TokenizerKind
- type TokenizerLevel
- type Type
Constants ¶
This section is empty.
Variables ¶
var ( // Buffers JStructScannerBufferSize = 4 * 1024 JSStructScannerBufferThreshold = JStructScannerBufferSize >> 3 )
var ( // UnmarshalJSON Func is injection point of json.Unmarshaller for JsonStruct UnmarshalJSON = UnmarshalJSONFn // MarshalJSON Func is injection point of json.Marshaller for JsonStruct MarshalJSON = MarshalJSONFn // JStructParse Func provides io.Reader based parsing of JSON data JStructParse = JStructParseFn // JStructSerialize Func provides io.Writer based serialization of JSON data JStructSerialize = JStructSerializeFn )
Injection points for testing purpose and custom implementation. If you would like to override JSON marshal/unmarshal implementation, please follow bellow approach.
js.UnmarshalJSON = func (bytes []byte, v js.JStructOps) error { ... }
js.MarshalJSON = func (v js.JStructOps) ([]byte, error) { ... }
var IndexOutOfRangeError = errors.New("JsonStruct: index out of range")
var InvalidCharacterError = errors.New("JsonStruct: invalid character")
var InvalidEscapeCharacterError = errors.New("JsonStruct: invalid escape character")
var InvalidHexNumberError = errors.New("JsonStruct: invalid hex number")
var NotArrayError = errors.New("JsonStruct: not an array, set explicitly")
var NotObjectError = errors.New("JsonStruct: not an object, set explicitly")
var OffsetOutOfRangeError = errors.New("JStructReader: offset out of range")
var UnsupportedTypeError = errors.New("JsonStruct: unsupported value type, resolved as null")
Functions ¶
func JStructParseFn ¶
func JStructParseFn(rd io.Reader, v JStructOps) (e error)
func JStructSerializeFn ¶
func JStructSerializeFn(v JStructOps, wr io.Writer) (e error)
func MarshalJSONFn ¶
func MarshalJSONFn(v JStructOps) ([]byte, error)
func ParsePrimitiveValue ¶
func ParsePrimitiveValue(bt byte, rd *bufio.Reader, v JStructOps) (e error)
func UnmarshalJSONFn ¶
func UnmarshalJSONFn(b []byte, v JStructOps) error
Types ¶
type ArrayOps ¶
type ArrayOps interface {
Push(interface{}) error
Pop() JStructOps
Shift() JStructOps
SetIndex(int, interface{}) error
GetIndex(int) JStructOps
}
type GeneralOps ¶
type InvalidJsonError ¶
type InvalidJsonError struct {
Err error
}
func (InvalidJsonError) Error ¶
func (i InvalidJsonError) Error() string
type InvalidJsonPtrError ¶
func (InvalidJsonPtrError) Error ¶
func (i InvalidJsonPtrError) Error() string
type InvalidJsonTokenPtrError ¶
func (InvalidJsonTokenPtrError) Error ¶
func (i InvalidJsonTokenPtrError) Error() string
type JStructConvertibleOps ¶
type JStructConvertibleOps interface {
GeneralOps
PrimitiveOps
ObjectOps
ArrayOps
json.Unmarshaler
json.Marshaler
}
type JStructOps ¶
type JStructOps interface {
GeneralOps
PrimitiveOps
ObjectOps
ArrayOps
}
type JStructScanner ¶
type JStructScanner interface {
Current() byte // show from buffer
Bytes() []byte // copy to data and release
Next() error // scan 1 byte
Scan(n int) error // move pointer, if required read data
Index() int // position in file
Buffer() []byte // current buffer
Window() (int, int) // window of current buffer (start, end)
FillBuffFrom(idx int) (int, error) // fill buffer from idx, should be in interval [start, size)
}
func NewJStructScanner ¶
func NewJStructScanner(rd io.Reader) JStructScanner
func NewJStructScannerWithParam ¶
func NewJStructScannerWithParam(rd io.Reader, size, threshold int) JStructScanner
type JStructScannerImpl ¶
type JStructScannerImpl struct {
// contains filtered or unexported fields
}
func (*JStructScannerImpl) Buffer ¶
func (j *JStructScannerImpl) Buffer() []byte
Buffer returns current buffer
func (*JStructScannerImpl) Bytes ¶
func (j *JStructScannerImpl) Bytes() []byte
Bytes returns data in window (start, ptr)
func (*JStructScannerImpl) Current ¶
func (j *JStructScannerImpl) Current() byte
Current returns pointed byte
func (*JStructScannerImpl) FillBuffFrom ¶
func (j *JStructScannerImpl) FillBuffFrom(idx int) (int, error)
func (*JStructScannerImpl) Index ¶
func (j *JStructScannerImpl) Index() int
Index returns current position in file
func (*JStructScannerImpl) Next ¶
func (j *JStructScannerImpl) Next() error
func (*JStructScannerImpl) Scan ¶
func (j *JStructScannerImpl) Scan(n int) error
func (*JStructScannerImpl) Window ¶
func (j *JStructScannerImpl) Window() (int, int)
Window returns window of current buffer (start, ptr)
type JStructTokenizer ¶
type JStructTokenizer interface {
Next() error
Value() []byte
Kind() TokenizerKind
Level() TokenizerLevel
}
func NewJStructTokenizer ¶
func NewJStructTokenizer(sc JStructScanner) JStructTokenizer
type JStructTokenizerImpl ¶
type JStructTokenizerImpl struct {
// contains filtered or unexported fields
}
func (*JStructTokenizerImpl) Kind ¶
func (t *JStructTokenizerImpl) Kind() TokenizerKind
func (*JStructTokenizerImpl) Level ¶
func (t *JStructTokenizerImpl) Level() TokenizerLevel
func (*JStructTokenizerImpl) Next ¶
func (t *JStructTokenizerImpl) Next() error
func (*JStructTokenizerImpl) PopLevel ¶
func (t *JStructTokenizerImpl) PopLevel()
PopLevel pops the current level from the stack and sets the new level to the popped value
func (*JStructTokenizerImpl) PushLevel ¶
func (t *JStructTokenizerImpl) PushLevel(l TokenizerLevel)
PushLevel pushes the current level to the stack and sets the new level to the given value
func (*JStructTokenizerImpl) ReadExponentPart ¶
func (t *JStructTokenizerImpl) ReadExponentPart(firstIdx int) error
func (*JStructTokenizerImpl) ReadFalse ¶
func (t *JStructTokenizerImpl) ReadFalse() error
func (*JStructTokenizerImpl) ReadFractionPart ¶
func (t *JStructTokenizerImpl) ReadFractionPart(firstIdx int) error
func (*JStructTokenizerImpl) ReadNull ¶
func (t *JStructTokenizerImpl) ReadNull() error
func (*JStructTokenizerImpl) ReadNumber ¶
func (t *JStructTokenizerImpl) ReadNumber(hasMinus bool) error
func (*JStructTokenizerImpl) ReadString ¶
func (t *JStructTokenizerImpl) ReadString() error
func (*JStructTokenizerImpl) ReadStringTime ¶
func (t *JStructTokenizerImpl) ReadStringTime() error
Read json string or time in RFC3339 format
func (*JStructTokenizerImpl) ReadTrue ¶
func (t *JStructTokenizerImpl) ReadTrue() error
func (*JStructTokenizerImpl) Value ¶
func (t *JStructTokenizerImpl) Value() []byte
type JsonStruct ¶
type JsonStruct struct {
// contains filtered or unexported fields
}
JsonStruct is a struct that can be converted to JSON. It implements the json.Marshaler and json.Unmarshaler interfaces. // It also implements the sql.Scanner and sql.Valuer interfaces. It supports JSON types like:
- string
- int / int64
- float64
- bool
- [extra] DateTime (ISO 8601, rfc3339)
- Object
- Array
func (*JsonStruct) AsArray ¶
func (s *JsonStruct) AsArray()
func (*JsonStruct) AsObject ¶
func (s *JsonStruct) AsObject()
func (*JsonStruct) Bool ¶
func (s *JsonStruct) Bool() bool
func (*JsonStruct) Float ¶
func (s *JsonStruct) Float() float64
func (*JsonStruct) GetIndex ¶
func (s *JsonStruct) GetIndex(i int) JStructOps
func (*JsonStruct) GetKey ¶
func (s *JsonStruct) GetKey(key string) JStructOps
func (*JsonStruct) HasKey ¶
func (s *JsonStruct) HasKey(key string) bool
func (*JsonStruct) Int ¶
func (s *JsonStruct) Int() int64
func (*JsonStruct) IsArray ¶
func (s *JsonStruct) IsArray() bool
func (*JsonStruct) IsBool ¶
func (s *JsonStruct) IsBool() bool
func (*JsonStruct) IsFloat ¶
func (s *JsonStruct) IsFloat() bool
func (*JsonStruct) IsInt ¶
func (s *JsonStruct) IsInt() bool
func (*JsonStruct) IsNull ¶
func (s *JsonStruct) IsNull() bool
func (*JsonStruct) IsNumber ¶
func (s *JsonStruct) IsNumber() bool
func (*JsonStruct) IsObject ¶
func (s *JsonStruct) IsObject() bool
func (*JsonStruct) IsString ¶
func (s *JsonStruct) IsString() bool
func (*JsonStruct) IsTime ¶
func (s *JsonStruct) IsTime() bool
func (*JsonStruct) IsUint ¶
func (s *JsonStruct) IsUint() bool
func (*JsonStruct) Keys ¶
func (s *JsonStruct) Keys() []string
func (*JsonStruct) MarshalJSON ¶
func (s *JsonStruct) MarshalJSON() ([]byte, error)
func (*JsonStruct) Pop ¶
func (s *JsonStruct) Pop() JStructOps
func (*JsonStruct) Push ¶
func (s *JsonStruct) Push(v interface{}) error
func (*JsonStruct) RemoveKey ¶
func (s *JsonStruct) RemoveKey(key string) JStructOps
func (*JsonStruct) SetBool ¶
func (s *JsonStruct) SetBool(v bool)
func (*JsonStruct) SetFloat ¶
func (s *JsonStruct) SetFloat(v float64)
func (*JsonStruct) SetIndex ¶
func (s *JsonStruct) SetIndex(i int, v interface{}) error
func (*JsonStruct) SetInt ¶
func (s *JsonStruct) SetInt(v int64)
func (*JsonStruct) SetKey ¶
func (s *JsonStruct) SetKey(key string, v interface{}) error
func (*JsonStruct) SetNull ¶
func (s *JsonStruct) SetNull()
func (*JsonStruct) SetString ¶
func (s *JsonStruct) SetString(v string)
func (*JsonStruct) SetTime ¶
func (s *JsonStruct) SetTime(v time.Time)
func (*JsonStruct) SetUint ¶
func (s *JsonStruct) SetUint(v uint64)
func (*JsonStruct) Shift ¶
func (s *JsonStruct) Shift() JStructOps
func (*JsonStruct) Size ¶
func (s *JsonStruct) Size() int
func (*JsonStruct) String ¶
func (s *JsonStruct) String() string
func (*JsonStruct) Time ¶
func (s *JsonStruct) Time() time.Time
func (*JsonStruct) Type ¶
func (s *JsonStruct) Type() Type
func (*JsonStruct) Uint ¶
func (s *JsonStruct) Uint() uint64
func (*JsonStruct) UnmarshalJSON ¶
func (s *JsonStruct) UnmarshalJSON(bytes []byte) error
func (*JsonStruct) Value ¶
func (s *JsonStruct) Value() interface{}
type ObjectOps ¶
type ObjectOps interface {
SetKey(string, interface{}) error
GetKey(string) JStructOps
RemoveKey(string) JStructOps
HasKey(string) bool
Keys() []string
}
type PrimitiveOps ¶
type PrimitiveOps interface {
IsBool() bool
SetBool(bool)
Bool() bool
IsNumber() bool
IsInt() bool
SetInt(int64)
Int() int64
IsUint() bool
SetUint(uint64)
Uint() uint64
IsFloat() bool
SetFloat(float64)
Float() float64
IsString() bool
SetString(string)
String() string
IsTime() bool
SetTime(time.Time)
Time() time.Time
}
type TokenizerKind ¶
type TokenizerKind byte
const ( KindUnknown TokenizerKind = iota KindNull KindFalse KindTrue KindNumber KindFloatNumber KindTime KindString KindLiteral )
func (TokenizerKind) String ¶
func (k TokenizerKind) String() string
type TokenizerLevel ¶
type TokenizerLevel byte
const ( LevelUnknown TokenizerLevel = iota LevelRoot LevelObject LevelObjectEnd LevelArray LevelArrayEnd LevelKey LevelValue LevelValueLast )
func (TokenizerLevel) String ¶
func (l TokenizerLevel) String() string