Documentation ¶
Overview ¶
Package resp provides Redis Serialization Protocol (RESP) encoding and decoding, including Data Transfer Objects (DTOs) for the protocol. The DTOs, once decoded or instantiated, are immutable and can be used concurrently.
Index ¶
- Constants
- Variables
- func Compare(l, r Value) int
- func Hash(v Value) uint64
- func ToBytes(v Value) []byte
- func ToString(v Value) string
- func V2Compatible(r *Reader)
- type Array
- type Attribute
- type BigNumber
- type Boolean
- type BulkError
- type BulkString
- type Collection
- type Counted
- type Double
- type Error
- type Hasher
- type Integer
- type MakeMappedKey
- type Map
- type Mapped
- type Null
- type Push
- type Reader
- type ReaderConfig
- type ReaderFunc
- type ReaderOption
- type Set
- func (s *Set) Attribute() *Attribute
- func (s *Set) Contains(v Value) bool
- func (s *Set) Count() int
- func (s *Set) Elements() Values
- func (s *Set) Equal(v Value) bool
- func (s *Set) ForEach(fn func(Value) error) error
- func (s *Set) Hash() uint64
- func (s *Set) Marshal(w io.Writer) error
- func (*Set) Tag() Tag
- func (s *Set) WithAttribute(attr *Attribute) Value
- type SimpleError
- type SimpleString
- type String
- type Tag
- type TopLevelOnly
- type Value
- type Values
- func (v Values) Contains(e Value) bool
- func (v Values) Count() int
- func (v Values) Elements() Values
- func (v Values) Equal(other Values) bool
- func (v Values) ForEach(fn func(Value) error) error
- func (v Values) Hash() uint64
- func (v Values) Sort() Values
- func (v Values) SortWith(cmp func(Value, Value) int) Values
- type VerbatimString
Constants ¶
View Source
const ( CR byte = 13 LF byte = 10 )
View Source
const ( ErrEmptyInput = "ERR empty input: %e" ErrUnknownTag = "ERR unknown tag: %s" ErrInvalidNesting = "ERR invalid nesting: %s" ErrInvalidLength = "ERR invalid length: %d" ErrInvalidTerminator = "ERR invalid terminator: %v" )
Error messages
View Source
const (
ErrInvalidBigNumber = "ERR invalid big number: %s"
)
Error messages
View Source
const (
ErrInvalidBoolean = "ERR invalid boolean: %s"
)
Error messages
View Source
const (
ErrInvalidEncoding = "invalid encoding: %s"
)
Error messages
View Source
const (
OK = SimpleString("OK")
)
Variables ¶
View Source
var ( ZeroInteger = Integer(0) ZeroDouble = Double(0) ZeroBigNumber = (*BigNumber)(new(big.Int).SetInt64(0)) )
View Source
var ( EmptySimpleString = SimpleString("") EmptyBulkString = BulkString("") )
View Source
var DefaultReaders = WithReaderFuncs(map[Tag]ReaderFunc{
SimpleStringTag: asValue(readSimpleString),
SimpleErrorTag: asValue(readSimpleError),
IntegerTag: asValue(readInteger),
BulkStringTag: asValue(readBulkString),
ArrayTag: asValue(readArray),
NullTag: asValue(readNull),
BooleanTag: asValue(readBoolean),
DoubleTag: asValue(readDouble),
BigNumberTag: asValue(readBigNumber),
BulkErrorTag: asValue(readBulkError),
VerbatimStringTag: asValue(readVerbatimString),
MapTag: asValue(readMap),
AttributeTag: asValue(readAttribute),
SetTag: asValue(readSet),
PushTag: asValue(readPush),
})
DefaultReaders adds the default RESP readers to the Reader
View Source
var (
EmptyArray = &Array{Values: Values{}}
)
View Source
var (
EmptyAttribute = &Attribute{mapped: newMapped(0)}
)
View Source
var (
EmptyMap = &Map{mapped: newMapped(0)}
)
View Source
var (
EmptyPush = &Push{Values: Values{}}
)
View Source
var ( EmptySet = &Set{ data: makeHashedArray[Value](0), } )
View Source
var ( EmptyVerbatimString = &VerbatimString{ data: []byte{}, enc: emptyEncoding, } )
View Source
var NewLine = []byte{CR, LF}
Functions ¶
Types ¶
type Attribute ¶
type Attribute struct {
// contains filtered or unexported fields
}
func MakeAttribute ¶
func MakeAttribute[K MakeMappedKey, V Value](m map[K]V) *Attribute
func MakeAttributeFromPairs ¶
type BigNumber ¶
func MakeBigNumber ¶
type BulkError ¶
type BulkError struct {
// contains filtered or unexported fields
}
func MakeBulkError ¶
type BulkString ¶
type BulkString string
func (BulkString) Equal ¶
func (s BulkString) Equal(v Value) bool
func (BulkString) String ¶
func (s BulkString) String() string
func (BulkString) Tag ¶
func (BulkString) Tag() Tag
type Collection ¶
type MakeMappedKey ¶
type MakeMappedKey interface { comparable Value }
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
func MakeMap ¶
func MakeMap[K MakeMappedKey, V Value](m map[K]V) *Map
func MakeMapFromPairs ¶
type Reader ¶
type Reader struct { ReaderConfig // contains filtered or unexported fields }
type ReaderConfig ¶
type ReaderConfig struct {
// contains filtered or unexported fields
}
type ReaderFunc ¶
type ReaderOption ¶
type ReaderOption func(*ReaderConfig)
func WithReaderFuncs ¶
func WithReaderFuncs(m map[Tag]ReaderFunc) ReaderOption
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
func (*Set) WithAttribute ¶
type SimpleError ¶
type SimpleError struct {
// contains filtered or unexported fields
}
func MakeSimpleError ¶
func MakeSimpleError(s string) *SimpleError
func (*SimpleError) Equal ¶
func (e *SimpleError) Equal(v Value) bool
func (*SimpleError) Tag ¶
func (*SimpleError) Tag() Tag
type SimpleString ¶
type SimpleString string
func (SimpleString) Equal ¶
func (s SimpleString) Equal(v Value) bool
func (SimpleString) String ¶
func (s SimpleString) String() string
func (SimpleString) Tag ¶
func (SimpleString) Tag() Tag
type String ¶
func MakeString ¶
type Tag ¶
type Tag byte
Tag represents a RESP value type, as a single prefix byte
const ( SimpleStringTag Tag = '+' // simple string SimpleErrorTag Tag = '-' // simple error IntegerTag Tag = ':' // integer BulkStringTag Tag = '$' // bulk string ArrayTag Tag = '*' // array NullTag Tag = '_' // null BooleanTag Tag = '#' // boolean DoubleTag Tag = ',' // double BigNumberTag Tag = '(' // big number BulkErrorTag Tag = '!' // bulk error VerbatimStringTag Tag = '=' // verbose string MapTag Tag = '%' // map AttributeTag Tag = '|' // attribute SetTag Tag = '~' // data PushTag Tag = '>' // push )
type TopLevelOnly ¶
type TopLevelOnly interface { Value // contains filtered or unexported methods }
type Value ¶
type Value interface { // Tag returns the type of the Value Tag() Tag // Marshal writes a readable representation of the Value to a provided // io.Writer. Implementations assume Writer is in some way buffered, // and may make multiple calls to Write to avoid building unnecessary // slices in memory Marshal(io.Writer) error // Equal compares the Value to another Value, returning true if Equal Equal(Value) bool }
Value represents a single RESP value
func ReadString ¶
func ReadString(s string, opts ...ReaderOption) (Value, error)
type VerbatimString ¶
type VerbatimString struct {
// contains filtered or unexported fields
}
func MakeVerbatimString ¶
func MakeVerbatimString(enc string, data string) (*VerbatimString, error)
func (*VerbatimString) Encoding ¶
func (s *VerbatimString) Encoding() string
func (*VerbatimString) Equal ¶
func (s *VerbatimString) Equal(v Value) bool
func (*VerbatimString) String ¶
func (s *VerbatimString) String() string
func (*VerbatimString) Tag ¶
func (*VerbatimString) Tag() Tag
Click to show internal directories.
Click to hide internal directories.