Documentation ¶
Index ¶
- Variables
- func TokenEquals(x, y Token) bool
- type Decoder
- type Encoder
- func (e *Encoder) Bytes() []byte
- func (e *Encoder) EndArray()
- func (e *Encoder) EndObject()
- func (e *Encoder) StartArray()
- func (e *Encoder) StartObject()
- func (e *Encoder) WriteBool(b bool)
- func (e *Encoder) WriteFloat(n float64, bitSize int)
- func (e *Encoder) WriteInt(n int64)
- func (e *Encoder) WriteName(s string) error
- func (e *Encoder) WriteNull()
- func (e *Encoder) WriteString(s string) error
- func (e *Encoder) WriteUint(n uint64)
- type Kind
- type Token
- func (t Token) Bool() bool
- func (t Token) Float(bitSize int) (float64, bool)
- func (t Token) Int(bitSize int) (int64, bool)
- func (t Token) Kind() Kind
- func (t Token) Name() string
- func (t Token) ParsedString() string
- func (t Token) Pos() int
- func (t Token) RawString() string
- func (t Token) Uint(bitSize int) (uint64, bool)
Constants ¶
This section is empty.
Variables ¶
var ErrUnexpectedEOF = errors.New("%v", io.ErrUnexpectedEOF)
ErrUnexpectedEOF means that EOF was encountered in the middle of the input.
Functions ¶
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder is a token-based JSON decoder.
func NewDecoder ¶
NewDecoder returns a Decoder to read the given []byte.
func (*Decoder) Clone ¶
Clone returns a copy of the Decoder for use in reading ahead the next JSON object, array or other values without affecting current Decoder.
func (*Decoder) Peek ¶
Peek looks ahead and returns the next token kind without advancing a read.
func (*Decoder) Position ¶
Position returns line and column number of given index of the original input. It will panic if index is out of range.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder provides methods to write out JSON constructs and values. The user is responsible for producing valid sequences of JSON constructs and values.
func NewEncoder ¶
NewEncoder returns an Encoder.
If indent is a non-empty string, it causes every entry for an Array or Object to be preceded by the indent and trailed by a newline.
func (*Encoder) Bytes ¶
Bytes returns the content of the written bytes.
func (*Encoder) StartObject ¶
func (e *Encoder) StartObject()
StartObject writes out the '{' symbol.
func (*Encoder) WriteBool ¶
WriteBool writes out the given boolean value.
func (*Encoder) WriteFloat ¶
WriteFloat writes out the given float and bitSize in JSON number value.
func (*Encoder) WriteInt ¶
WriteInt writes out the given signed integer in JSON number value.
func (*Encoder) WriteName ¶
WriteName writes out the given string in JSON string value and the name separator ':'. Returns error if input string contains invalid UTF-8, which should not be likely as protobuf field names should be valid.
func (*Encoder) WriteString ¶
WriteString writes out the given string in JSON string value. Returns error if input string contains invalid UTF-8.
type Token ¶
type Token struct {
// contains filtered or unexported fields
}
Token provides a parsed token kind and value.
Values are provided by the difference accessor methods. The accessor methods Name, Bool, and ParsedString will panic if called on the wrong kind. There are different accessor methods for the Number kind for converting to the appropriate Go numeric type and those methods have the ok return value.
func (Token) Bool ¶
Bool returns the bool value if token kind is Bool, else it panics.
func (Token) Float ¶
Float returns the floating-point number if token kind is Number.
The floating-point precision is specified by the bitSize parameter: 32 for float32 or 64 for float64. If bitSize=32, the result still has type float64, but it will be convertible to float32 without changing its value. It will return false if the number exceeds the floating point limits for given bitSize.
func (Token) Int ¶
Int returns the signed integer number if token is Number.
The given bitSize specifies the integer type that the result must fit into. It returns false if the number is not an integer value or if the result exceeds the limits for given bitSize.
func (Token) Name ¶
Name returns the object name if token is Name, else it panics.
func (Token) ParsedString ¶
ParsedString returns the string value for a JSON string token or the read value in string if token is not a string.
func (Token) RawString ¶
RawString returns the read value in string.
func (Token) Uint ¶
Uint returns the signed integer number if token is Number.
The given bitSize specifies the unsigned integer type that the result must fit into. It returns false if the number is not an unsigned integer value or if the result exceeds the limits for given bitSize.