jsontoken

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeNumber

func DecodeNumber(r *scratch.Reader) (codectools.TokenKind, int64, float64, error)

DecodeNumber will attempt to decode data in the format of a JSON numer from the reader. JSON is somewhat ambiguous about numbers: we'll return an int if we can, and a float if there's any decimal point involved. The boolean return indicates which kind of number we have: if true, we have an int (and the float return is invalid); if false, we have a float (and the int return is invalid).

func DecodeString

func DecodeString(r *scratch.Reader) (string, error)

DecodeString will attempt to decode data in the format of a JSON string from the reader. If the first byte read is not `"`, it is not a string at all, and an error is returned. Any other parse errors of json strings also result in error.

func DecodeStringBody

func DecodeStringBody(r *scratch.Reader) (string, error)

DecodeStringBody will attempt to decode data in the format of a JSON string from the reader, except it assumes that the leading `"` has already been consumed, and will similarly leave the trailing `"` unread (although it will check for its presence).

Implementation note: you'll find that this method is used in the Decoder's implementation, while DecodeString is actually not. This is because when doing a whole document parse, the leading `"` is always already consumed because it's how we discovered it's time to parse a string.

Types

type Decoder

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

func (*Decoder) Init

func (d *Decoder) Init(r io.Reader)

func (*Decoder) Step

func (d *Decoder) Step(budget *int64) (next *codectools.Token, err error)

type DecoderConfig

type DecoderConfig struct {
	AllowDanglingComma  bool // normal json: false; strict: false.
	AllowWhitespace     bool // normal json: true;  strict: false.
	AllowEscapedUnicode bool // normal json: true;  strict: false.
	ParseUtf8C8         bool // normal json: false; dag-json: true.
}

Jump to

Keyboard shortcuts

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