resp

package
v0.0.0-...-cf07a88 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2016 License: BSD-3-Clause Imports: 5 Imported by: 6

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 character is found while parsing an integer.
	ErrInvalidInteger = errors.New("resp: invalid integer character")

	// 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

func Decode

func Decode(r BytesReader) (interface{}, error)

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

func DecodeRequest

func DecodeRequest(r BytesReader) ([]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.

func Encode

func Encode(w io.Writer, v interface{}) error

Encode encode the value v and writes the serialized data to w.

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 BytesReader

type BytesReader interface {
	io.Reader
	io.ByteReader
	ReadBytes(byte) ([]byte, error)
}

BytesReader defines the methods required for the Decode* family of methods. Notably, a *bufio.Reader and a *bytes.Buffer both satisfy this interface.

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