protobuf: google.golang.org/protobuf/internal/encoding/json Index | Files

package json

import "google.golang.org/protobuf/internal/encoding/json"

Index

Package Files

decode.go decode_number.go decode_string.go decode_token.go encode.go

Variables

var ErrUnexpectedEOF = errors.New("%v", io.ErrUnexpectedEOF)

ErrUnexpectedEOF means that EOF was encountered in the middle of the input.

func TokenEquals Uses

func TokenEquals(x, y Token) bool

TokenEquals returns true if given Tokens are equal, else false.

type Decoder Uses

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

Decoder is a token-based JSON decoder.

func NewDecoder Uses

func NewDecoder(b []byte) *Decoder

NewDecoder returns a Decoder to read the given []byte.

func (*Decoder) Clone Uses

func (d *Decoder) Clone() *Decoder

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 Uses

func (d *Decoder) Peek() (Token, error)

Peek looks ahead and returns the next token kind without advancing a read.

func (*Decoder) Position Uses

func (d *Decoder) Position(idx int) (line int, column int)

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 Uses

func (d *Decoder) Read() (Token, error)

Read returns the next JSON token. It will return an error if there is no valid token.

type Encoder Uses

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 Uses

func NewEncoder(indent string) (*Encoder, error)

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 Uses

func (e *Encoder) Bytes() []byte

Bytes returns the content of the written bytes.

func (*Encoder) EndArray Uses

func (e *Encoder) EndArray()

EndArray writes out the ']' symbol.

func (*Encoder) EndObject Uses

func (e *Encoder) EndObject()

EndObject writes out the '}' symbol.

func (*Encoder) StartArray Uses

func (e *Encoder) StartArray()

StartArray writes out the '[' symbol.

func (*Encoder) StartObject Uses

func (e *Encoder) StartObject()

StartObject writes out the '{' symbol.

func (*Encoder) WriteBool Uses

func (e *Encoder) WriteBool(b bool)

WriteBool writes out the given boolean value.

func (*Encoder) WriteFloat Uses

func (e *Encoder) WriteFloat(n float64, bitSize int)

WriteFloat writes out the given float and bitSize in JSON number value.

func (*Encoder) WriteInt Uses

func (e *Encoder) WriteInt(n int64)

WriteInt writes out the given signed integer in JSON number value.

func (*Encoder) WriteName Uses

func (e *Encoder) WriteName(s string) error

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 Uses

func (e *Encoder) WriteNull()

WriteNull writes out the null value.

func (*Encoder) WriteString Uses

func (e *Encoder) WriteString(s string) error

WriteString writes out the given string in JSON string value. Returns error if input string contains invalid UTF-8.

func (*Encoder) WriteUint Uses

func (e *Encoder) WriteUint(n uint64)

WriteUint writes out the given unsigned integer in JSON number value.

type Kind Uses

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 Uses

func (k Kind) String() string

type Token Uses

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 Uses

func (t Token) Bool() bool

Bool returns the bool value if token kind is Bool, else it panics.

func (Token) Float Uses

func (t Token) Float(bitSize int) (float64, bool)

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 Uses

func (t Token) Int(bitSize int) (int64, bool)

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 Uses

func (t Token) Kind() Kind

Kind returns the token kind.

func (Token) Name Uses

func (t Token) Name() string

Name returns the object name if token is Name, else it will return an error.

func (Token) ParsedString Uses

func (t Token) ParsedString() string

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 Uses

func (t Token) Pos() int

Pos returns the token position from the input.

func (Token) RawString Uses

func (t Token) RawString() string

RawString returns the read value in string.

func (Token) Uint Uses

func (t Token) Uint(bitSize int) (uint64, bool)

Uint returns the signed integer number if token is Number, else it will return an error.

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.

Package json imports 14 packages (graph) and is imported by 2 packages. Updated 2020-08-08. Refresh now. Tools for package owners.