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 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") )
var ErrInvalidValue = errors.New("resp: invalid value")
ErrInvalidValue is returned if the value to encode is invalid.
Functions ¶
This section is empty.
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 Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder decodes values received by an io.Reader.
func NewDecoder ¶
NewDecoder returns a new Decoder that reads values from r.
func (*Decoder) DecodeRequest ¶
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 ¶
NewEncoder returns a new Encoder that writes to w.
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.