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 ¶
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") )
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.
Types ¶
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 ¶
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.