package json
import "google.golang.org/protobuf/internal/encoding/json"
Index ¶
- Variables
- func TokenEquals(x, y Token) bool
- type Decoder
- func NewDecoder(b []byte) *Decoder
- func (d *Decoder) Clone() *Decoder
- func (d *Decoder) Peek() (Token, error)
- func (d *Decoder) Position(idx int) (line int, column int)
- func (d *Decoder) Read() (Token, error)
- type Encoder
- func NewEncoder(buf []byte, indent string) (*Encoder, error)
- 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)
Variables ¶
var ErrUnexpectedEOF = errors.New("%v", io.ErrUnexpectedEOF)
ErrUnexpectedEOF means that EOF was encountered in the middle of the input.
Functions ¶
func TokenEquals ¶
TokenEquals returns true if given Tokens are equal, else false.
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.
func (*Decoder) Read ¶
Read returns the next JSON token. It will return an error if there is no valid token.
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) EndArray ¶
func (e *Encoder) EndArray()
EndArray writes out the ']' symbol.
func (*Encoder) EndObject ¶
func (e *Encoder) EndObject()
EndObject writes out the '}' symbol.
func (*Encoder) StartArray ¶
func (e *Encoder) StartArray()
StartArray writes out the '[' symbol.
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) WriteNull ¶
func (e *Encoder) WriteNull()
WriteNull writes out the null value.
func (*Encoder) WriteString ¶
WriteString writes out the given string in JSON string value. Returns error if input string contains invalid UTF-8.
func (*Encoder) WriteUint ¶
WriteUint writes out the given unsigned integer in JSON number value.
type Kind ¶
type Kind uint16
Kind represents a token kind expressible in the JSON format.
const ( Invalid Kind = (1 << iota) / 2 EOF Null Bool Number String Name ObjectOpen ObjectClose ArrayOpen ArrayClose )
func (Kind) String ¶
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) Kind ¶
Kind returns the token kind.
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) Pos ¶
Pos returns the token position from the input.
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.
Source Files ¶
decode.go decode_number.go decode_string.go decode_token.go encode.go
- Version
- v1.36.5 (latest)
- Published
- Feb 6, 2025
- Platform
- linux/amd64
- Imports
- 14 packages
- Last checked
- 10 hours ago –
Tools for package owners.