decoder

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLineTooLong = errors.New("Line exceeded permitted length")

Functions

This section is empty.

Types

type Decoder

type Decoder interface {
	Decode(v interface{}) error
}

type JSONDecodeError

type JSONDecodeError string

JSONDecodeError is a custom error that can occur during JSON decoding

func (JSONDecodeError) Error

func (s JSONDecodeError) Error() string

type JSONDecoder

type JSONDecoder struct {
	*jsoniter.Decoder
	// contains filtered or unexported fields
}

func NewJSONDecoder

func NewJSONDecoder(r io.Reader) JSONDecoder

NewJSONDecoder returns a *json.Decoder where numbers are unmarshaled as a Number instead of a float64 into an interface{}

type LimitedReader

type LimitedReader struct {
	R io.Reader

	N int64
	// contains filtered or unexported fields
}

LimitedReader is like io.LimitedReader, but returns a requestError upon detecting a request that is too large.

Based on net/http.maxBytesReader.

func (*LimitedReader) Read

func (l *LimitedReader) Read(p []byte) (n int, err error)

Read implements the standard Read interface, returning an error if more than l.N bytes are read.

After each read, l.N is decremented by the number of bytes read; if an error is returned due to the l.N limit being exceeded, on return l.N will be set to a negative value.

type LineReader

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

LineReader reads length-limited lines from streams using a limited amount of memory.

func NewLineReader

func NewLineReader(reader *bufio.Reader, maxLineLength int) *LineReader

func (*LineReader) ReadLine

func (lr *LineReader) ReadLine() ([]byte, error)

ReadLine reads the next line from the given reader. If it encounters a line that is longer than `maxLineLength` it will return the first `maxLineLength` bytes with `ErrLineTooLong`. On the next call it will return the next line.

func (*LineReader) Reset

func (lr *LineReader) Reset(br *bufio.Reader)

Reset sets lr's underlying *bufio.Reader to br, and clears any state.

type NDJSONStreamDecoder

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

NDJSONStreamDecoder decodes a stream of ND-JSON lines from an io.Reader.

func NewNDJSONStreamDecoder

func NewNDJSONStreamDecoder(r io.Reader, maxLineLength int) *NDJSONStreamDecoder

NewNDJSONStreamDecoder returns a new NDJSONStreamDecoder which decodes ND-JSON lines from r, with a maximum line length of maxLineLength.

func (*NDJSONStreamDecoder) Decode

func (dec *NDJSONStreamDecoder) Decode(v interface{}) error

Decode decodes the next line into v.

func (*NDJSONStreamDecoder) IsEOF

func (dec *NDJSONStreamDecoder) IsEOF() bool

IsEOF signals whether the underlying reader reached the end

func (*NDJSONStreamDecoder) LatestLine

func (dec *NDJSONStreamDecoder) LatestLine() []byte

LatestLine returns the latest line read as []byte

func (*NDJSONStreamDecoder) ReadAhead

func (dec *NDJSONStreamDecoder) ReadAhead() ([]byte, error)

ReadAhead reads the next NDJSON line, buffering it for a subsequent call to Decode.

func (*NDJSONStreamDecoder) Reset

func (dec *NDJSONStreamDecoder) Reset(r io.Reader)

Reset sets sr's underlying io.Reader to r, and resets any reading/decoding state.

Jump to

Keyboard shortcuts

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