resp

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2017 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package resp implements an efficient decoder for the Redis Serialization Protocol (RESP).

See http://redis.io/topics/protocol for the reference.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidPrefix is returned if the data contains an unrecognized prefix.
	ErrInvalidPrefix = errors.New("resp: invalid prefix")

	// ErrMissingCRLF is returned if a \r\n is missing in the data slice.
	ErrMissingCRLF = errors.New("resp: missing CRLF")

	// ErrInvalidInteger is returned if an invalid value is found while parsing an integer.
	ErrInvalidInteger = errors.New("resp: invalid integer value")

	// ErrInvalidBulkString is returned if the bulk string data cannot be decoded.
	ErrInvalidBulkString = errors.New("resp: invalid bulk string")

	// ErrInvalidArray is returned if the array data cannot be decoded.
	ErrInvalidArray = errors.New("resp: invalid array")

	// ErrNotAnArray is returned if the DecodeRequest function is called and
	// the decoded value is not an array.
	ErrNotAnArray = errors.New("resp: expected an array type")

	// ErrInvalidRequest is returned if the DecodeRequest function is called and
	// the decoded value is not an array containing only bulk strings, and at least 1 element.
	ErrInvalidRequest = errors.New("resp: invalid request, must be an array of bulk strings with at least one element")
)
View Source
var ErrInvalidValue = errors.New("resp: invalid value")

ErrInvalidValue is returned if the value to encode is invalid.

Functions

This section is empty.

Types

type Array

type Array []interface{}

Array represents an array of values, as defined by the RESP.

func (Array) String

func (a Array) String() string

String is the Stringer implementation for the Array.

type BulkString

type BulkString string

BulkString represents a binary-safe string as defined by the RESP. It can be used as a type conversion so that Encode serializes the string as a BulkString, but this is the default encoding for a normal Go string.

type Decoder

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

Decoder decodes values received by an io.Reader.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new Decoder that reads values from r.

func (*Decoder) Decode

func (d *Decoder) Decode() (interface{}, error)

Decode decodes the provided byte slice and returns the parsed value.

func (*Decoder) DecodeRequest

func (d *Decoder) DecodeRequest() ([]string, error)

DecodeRequest decodes the provided byte slice and returns the array representing the request. If the encoded value is not an array, it returns ErrNotAnArray, and if it is not a valid request, it returns ErrInvalidRequest.

type Encoder

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

Encoder encodes values to the Redis serialization protocol.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new Encoder that writes to w.

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) error

Encode encodes the value v.

type Error

type Error string

Error represents an error string as defined by the RESP. It cannot contain \r or \n characters. It must be used as a type conversion so that Encode serializes the string as an Error.

type OK

type OK struct{}

OK is a sentinel type used to indicate that the OK simple string value should be encoded.

type Pong

type Pong struct{}

Pong is a sentinel type used to indicate that the PONG simple string value should be encoded.

type SimpleString

type SimpleString string

SimpleString represents a simple string as defined by the RESP. It cannot contain \r or \n characters. It must be used as a type conversion so that Encode serializes the string as a SimpleString.

Jump to

Keyboard shortcuts

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