Documentation ¶
Overview ¶
Package resp provides RESP protocol serialization and deserialization
Index ¶
- Constants
- Variables
- type Any
- type Appender
- type Array
- func (a Array) AppendRESP(buf []byte) []byte
- func (a Array) BulkStringArray() (BulkStringArray, error)
- func (a Array) BulkStringMap() (BulkStringMap, error)
- func (a Array) Decode(x interface{}) error
- func (a Array) Len() int
- func (a Array) Null() bool
- func (Array) Type() Type
- func (a *Array) UnmarshalRESP(v Value) error
- type Buffer
- func (b *Buffer) AppendRESP(buf []byte) []byte
- func (b *Buffer) Array(arr ...Any)
- func (b *Buffer) BulkString(s string)
- func (b *Buffer) BulkStringArray(s ...string)
- func (b *Buffer) BulkStringBytes(data []byte)
- func (b *Buffer) Err(msg string)
- func (b *Buffer) Int(n int64)
- func (b *Buffer) SimpleString(s string)
- type BulkString
- type BulkStringArray
- type BulkStringBytes
- type BulkStringMap
- type DecodeError
- type Error
- type Integer
- type Iter
- type Message
- func (msg *Message) Any() Any
- func (msg *Message) AppendRESP(buf []byte) []byte
- func (msg *Message) Parse(buf []byte) (Value, error)
- func (msg *Message) ParseString(str string) (Value, error)
- func (msg *Message) ReadFrom(r *bufio.Reader) (Value, error)
- func (msg *Message) Reset()
- func (msg *Message) Value() Value
- type NopUnmarshaler
- type ProtocolError
- type SimpleString
- type SimpleStringRecord
- type Stream
- type Tee
- type Type
- type Unmarshaler
- type Value
- func (v Value) Any() Any
- func (v Value) AppendRESP(buf []byte) []byte
- func (v Value) BulkString() (BulkString, bool)
- func (v Value) Decode(x interface{}) error
- func (v Value) Each(fn func(v string) error) error
- func (v Value) EachKV(fn func(k, v string) error) error
- func (v Value) Err() error
- func (v Value) Integer() (int64, bool)
- func (v Value) IsZero() bool
- func (v Value) Iter() Iter
- func (v Value) Len() int64
- func (v Value) Null() bool
- func (v Value) NullArray() bool
- func (v Value) NullBulkString() bool
- func (v Value) SimpleString() (string, bool)
- func (v Value) Type() Type
- type Writer
- func (w *Writer) Available() int
- func (w *Writer) Buffered() int
- func (w *Writer) Err() error
- func (w *Writer) Flush() error
- func (w *Writer) Reset(dest io.Writer)
- func (w *Writer) Size() int
- func (w *Writer) WriteArray(i int64) error
- func (w *Writer) WriteBulkString(s string) error
- func (w *Writer) WriteBulkStringBytes(s []byte) error
- func (w *Writer) WriteBulkStringFloat(f float64) error
- func (w *Writer) WriteBulkStringInt(n int64) error
- func (w *Writer) WriteBulkStringNull() error
- func (w *Writer) WriteBulkStringPrefix(prefix, s string) error
- func (w *Writer) WriteBulkStringUint(n uint64) error
- func (w *Writer) WriteError(s string) error
- func (w *Writer) WriteInteger(i int64) error
- func (w *Writer) WriteSimpleString(s string) error
Constants ¶
const CRLF = "\r\n"
CRLF is the line ending used in RESP
const MaxBulkStringSize = 512 * 1024 * 1024 // 512 mb
MaxBulkStringSize is the maximum bulk string size specifed in the RESP Protocol
Variables ¶
var (
ErrNull = errors.New("Null")
)
Functions ¶
This section is empty.
Types ¶
type Any ¶
type Any interface { Type() Type Decode(x interface{}) error Appender // contains filtered or unexported methods }
Any is the interface of all RESP values
type Array ¶
type Array []Any
Array is a RESP array value
func (Array) AppendRESP ¶
AppendRESP implements Appender interface
func (Array) BulkStringArray ¶
func (a Array) BulkStringArray() (BulkStringArray, error)
BulkStringArray converts a RESP array to a slice of strings
func (Array) BulkStringMap ¶
func (a Array) BulkStringMap() (BulkStringMap, error)
BulkStringMap converts a RESP array of consecutive non null bulk string pairs to a map
func (*Array) UnmarshalRESP ¶
UnmarshalRESP implements Unmarshaler interface
type Buffer ¶
type Buffer struct {
B []byte
}
func (*Buffer) AppendRESP ¶
func (*Buffer) BulkString ¶
func (*Buffer) BulkStringArray ¶
func (*Buffer) BulkStringBytes ¶
func (*Buffer) SimpleString ¶
type BulkString ¶
BulkString is a RESP bulk string value
func (*BulkString) AppendRESP ¶
func (s *BulkString) AppendRESP(buf []byte) []byte
func (*BulkString) Decode ¶
func (s *BulkString) Decode(x interface{}) error
Decode implements Value interface
func (*BulkString) UnmarshalRESP ¶
func (s *BulkString) UnmarshalRESP(v Value) error
UnmarshalRESP implements Unmarshaler interface
type BulkStringArray ¶
type BulkStringArray []string
BulkStringArray is RESP array containing non null bulk strings
func (BulkStringArray) AppendRESP ¶
func (a BulkStringArray) AppendRESP(buf []byte) []byte
AppendRESP implements Appender interface
func (BulkStringArray) EachKV ¶
func (a BulkStringArray) EachKV(fn func(k, v string) error) (err error)
EachKV calls fn for each key/value pair in an array
func (BulkStringArray) Get ¶
func (a BulkStringArray) Get(key string) (string, bool)
Get treats the array as a map of consecutive key/value pairs
func (*BulkStringArray) UnmarshalRESP ¶
func (a *BulkStringArray) UnmarshalRESP(v Value) error
UnmarshalRESP implements Unmarshaler interface
type BulkStringBytes ¶
type BulkStringBytes []byte
BulkStringBytes is a buffer of a bulk string
func (BulkStringBytes) AppendRESP ¶
func (raw BulkStringBytes) AppendRESP(buf []byte) []byte
AppendRESP implements Appender interface
func (*BulkStringBytes) UnmarshalRESP ¶
func (raw *BulkStringBytes) UnmarshalRESP(v Value) error
UnmarshalRESP implements Unmarshaler interface
type BulkStringMap ¶
BulkStringMap is RESP map containing non null bulk strings
func (BulkStringMap) AppendRESP ¶
func (m BulkStringMap) AppendRESP(buf []byte) []byte
AppendRESP implements Appender interface
func (*BulkStringMap) UnmarshalRESP ¶
func (m *BulkStringMap) UnmarshalRESP(v Value) error
UnmarshalRESP implements Unmarshaler interface
type DecodeError ¶
func (*DecodeError) Error ¶
func (d *DecodeError) Error() string
func (*DecodeError) Unwrap ¶
func (d *DecodeError) Unwrap() error
type Error ¶
type Error string
Error is a RESP error value
func (Error) AppendRESP ¶
AppendRESP implements Appender interface
func (*Error) UnmarshalRESP ¶
UnmarshalRESP implements Unmarshaler interface
type Integer ¶
type Integer int64
Integer is a RESP integer value
func (Integer) AppendRESP ¶
AppendRESP implements Appender interface
func (*Integer) UnmarshalRESP ¶
UnmarshalRESP implements Unmarshaler interface
type Iter ¶
type Iter struct {
// contains filtered or unexported fields
}
Iter iterates over an array of RESP values
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message is a reply for a redis command.
func (*Message) AppendRESP ¶
AppendRESP implements Appender interface
func (*Message) ParseString ¶
ParseString parses a RESP value from a string
type NopUnmarshaler ¶
type NopUnmarshaler struct{}
func (NopUnmarshaler) UnmarshalRESP ¶
func (NopUnmarshaler) UnmarshalRESP(_ Value) error
type ProtocolError ¶
type ProtocolError struct {
Message string
}
ProtocolError is a RESP protocol error
func (*ProtocolError) Error ¶
func (e *ProtocolError) Error() string
func (*ProtocolError) String ¶
func (e *ProtocolError) String() string
type SimpleString ¶
type SimpleString string
SimpleString is a RESP simple string value
func (SimpleString) AppendRESP ¶
func (s SimpleString) AppendRESP(buf []byte) []byte
AppendRESP implements Appender interface
func (SimpleString) Check ¶
func (s SimpleString) Check() error
func (SimpleString) Decode ¶
func (s SimpleString) Decode(x interface{}) error
Decode implements Value interface
func (*SimpleString) UnmarshalRESP ¶
func (s *SimpleString) UnmarshalRESP(v Value) error
UnmarshalRESP implements Unmarshaler interface
type SimpleStringRecord ¶
func (*SimpleStringRecord) UnmarshalRESP ¶
func (m *SimpleStringRecord) UnmarshalRESP(v Value) error
type Tee ¶
type Tee []Unmarshaler
func (Tee) Concat ¶
func (tee Tee) Concat(u ...Unmarshaler) Tee
func (Tee) UnmarshalRESP ¶
type Type ¶
type Type byte
Type is the type of a RESP value
type Unmarshaler ¶
Unmarshaler can unmarshal from a RESP value
func Once ¶
func Once(dest interface{}) Unmarshaler
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is handle to a value in a RESP reply.
func (Value) AppendRESP ¶
AppendRESP implements Appender interface
func (Value) BulkString ¶
func (v Value) BulkString() (BulkString, bool)
BulkString returns a RESP bulk string value
func (Value) NullBulkString ¶
NullBulkString checks if a value is a null bulk string
func (Value) SimpleString ¶
SimpleString returns a RESP simple string value
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is a buffered writer for the RESP protocol.
It provides helper methods to write RESP messages with minimum copying and allocations. All writes are buffered up to a specified size. An explicit call to `Flush()` is required to write all data to the underlying `io.Writer`. The writer acts like `bufio.Writer` but avoids duplicate buffering during RESP protocol serialization.
func NewWriterSize ¶
NewWriterSize creates a new writer using the specified buffer size. A minimum buffer size of 512 bytes is enforced to allow enough space for RESP serialization without exceeding the buffer's capacity.
func (*Writer) Available ¶
Available returns the size available before data is flushed to the underlying `io.Writer`
func (*Writer) Flush ¶
Flush writes all buffered data to the underlying `io.Writer` and empties the buffer.
func (*Writer) Reset ¶
Reset resets the underlying `io.Writer`. This discards any buffered data and retains the buffer's capacity
func (*Writer) WriteArray ¶
WriteArray writes a RESP array with size `i`
func (*Writer) WriteBulkString ¶
WriteBulkString writes `s` as a RESP bulk string
func (*Writer) WriteBulkStringBytes ¶
WriteBulkStringBytes writes `s` as a RESP bulk string
func (*Writer) WriteBulkStringFloat ¶
WriteBulkStringFloat writes `f` as a RESP bulk string
func (*Writer) WriteBulkStringInt ¶
WriteBulkStringInt writes `n` as a RESP bulk string
func (*Writer) WriteBulkStringNull ¶
WriteBulkStringNull writes a null RESP bulk string
func (*Writer) WriteBulkStringPrefix ¶
WriteBulkStringPrefix writes `s` prefixed by `prefix` as a RESP bulk string
func (*Writer) WriteBulkStringUint ¶
WriteBulkStringUint writes `n` as a RESP bulk string
func (*Writer) WriteError ¶
WriteError writes `s` as a RESP error string
func (*Writer) WriteInteger ¶
WriteInteger writes `i` as a RESP integer
func (*Writer) WriteSimpleString ¶
WriteSimpleString writes `s` as a RESP simple string