resp

package
v4.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: MIT Imports: 3 Imported by: 2

Documentation

Overview

Package resp contains types and utilities useful for interacting with RESP protocols, without actually implementing any RESP protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrConnUnusable

func ErrConnUnusable(err error) error

ErrConnUnusable takes an existing error and, if it is wrapped in an ErrConnUsable, unwraps the ErrConnUsable from around it.

Types

type BufferedReader

type BufferedReader interface {
	io.Reader
	ReadSlice(delim byte) (line []byte, err error)
	Peek(n int) ([]byte, error)
	Discard(n int) (discarded int, err error)
}

BufferedReader wraps a bufio.Reader.

type BufferedWriter

type BufferedWriter interface {
	io.Writer
	Flush() error
}

BufferedWriter wraps a bufio.Writer.

type ErrConnUsable

type ErrConnUsable struct {
	Err error
}

ErrConnUsable is used to wrap an error encountered while marshaling or unmarshaling a message on a connection. It indicates that the network connection is still healthy and that there are no partially written/read messages on the stream.

func (ErrConnUsable) Error

func (ed ErrConnUsable) Error() string

func (ErrConnUsable) Unwrap

func (ed ErrConnUsable) Unwrap() error

Unwrap implements the errors.Wrapper interface.

type LenReader

type LenReader interface {
	io.Reader
	Len() int
}

LenReader adds an additional method to io.Reader, returning how many bytes are left till be read until an io.EOF is reached.

func NewLenReader

func NewLenReader(r io.Reader, l int) LenReader

NewLenReader wraps an existing io.Reader whose length is known so that it implements LenReader

type Marshaler

type Marshaler interface {
	MarshalRESP(io.Writer, *Opts) error
}

Marshaler is the interface implemented by types that can marshal themselves into valid RESP messages. Opts may not be nil.

NOTE It's important to keep track of whether a partial RESP message has been written to the Writer, and to use ErrConnUsable when returning errors if a partial RESP message has not been written.

type Opts

type Opts struct {
	// GetBytes returns a *[]byte from an internal pool, or a newly allocated
	// instance if the pool is empty. The returned instance will have a length
	// of zero.
	//
	// This field may not be nil.
	GetBytes func() *[]byte

	// PutBytes puts a *[]byte back into the pool so it can be re-used later via
	// GetBytes.
	//
	// This field may not be nil.
	PutBytes func(*[]byte)

	// GetReader returns an io.Reader which will read out the given bytes.
	//
	// This field may not be nil.
	GetReader func([]byte) io.Reader

	// GetBufferedReader returns a BufferedReader which will read out the
	// contents of the given io.Reader.
	//
	// This field may not be nil.
	GetBufferedReader func(r io.Reader) BufferedReader

	// GetBufferedWriter returns a BufferedWriter which will buffer writes to
	// the given io.Writer, such that calling Flush on it will ensure all
	// previous writes have been written.
	//
	// This field may not be nil.
	GetBufferedWriter func(w io.Writer) BufferedWriter

	// Deterministic indicates that marshal operations should result in
	// deterministic results. This is largely used for ensuring map key/values
	// are emitted in a deterministic order.
	Deterministic bool
}

Opts are used to aid and affect marshaling and unmarshaling of RESP messages. Opts are not expected to be thread-safe.

NewOpts should always be used to initialize a new Opts instance, even if some or all of the fields are expected to be changed. This way new fields may be added in the future without breaking existing usages.

func NewOpts

func NewOpts() *Opts

NewOpts returns an Opts instance which is suitable for most use-cases, and which may be modified if desired.

type Unmarshaler

type Unmarshaler interface {
	UnmarshalRESP(BufferedReader, *Opts) error
}

Unmarshaler is the interface implemented by types that can unmarshal a RESP message of themselves. Opts may not be nil.

NOTE It's important to keep track of whether a partial RESP message has been read off the BufferedReader, and to use ErrConnUsable when returning errors if a partial RESP message has not been read.

Directories

Path Synopsis
Package resp3 implements the upgraded redis RESP3 protocol, a plaintext protocol which is also binary safe and backwards compatible with the original RESP2 protocol.
Package resp3 implements the upgraded redis RESP3 protocol, a plaintext protocol which is also binary safe and backwards compatible with the original RESP2 protocol.

Jump to

Keyboard shortcuts

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