resp

package
v0.0.0-...-d6936bb Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 13 Imported by: 0

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

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 (
	NullValue = Null{}
	True      = Boolean(true)
	False     = Boolean(false)
)
View Source
var (
	EmptySimpleString = SimpleString("")
	EmptyBulkString   = BulkString("")

	EmptyVerbatimString = &VerbatimString{
		data: []byte{},
		enc:  emptyEncoding,
	}
)
View Source
var (
	EmptyArray = &Array{Values: Values{}}
	EmptyPush  = &Push{Values: Values{}}
)
View Source
var (
	EmptyMap = &Map{
		data: makeHashedArray[*mapPair](0),
	}
)
View Source
var (
	EmptySet = &Set{
		data: makeHashedArray[Value](0),
	}
)
View Source
var NewLine = []byte{CR, LF}

Functions

func Compare

func Compare(l, r Value) int

func Hash

func Hash(v Value) uint64

func ToString

func ToString(v Value) string

Types

type Aggregate

type Aggregate interface {
	Value
	// contains filtered or unexported methods
}

type Array

type Array struct {
	Values
	// contains filtered or unexported fields
}

func MakeArray

func MakeArray(v ...Value) *Array

func (*Array) Equal

func (a *Array) Equal(v Value) bool

func (*Array) Hash

func (a *Array) Hash() uint64

func (*Array) Marshal

func (a *Array) Marshal(w io.Writer) error

func (*Array) Tag

func (*Array) Tag() Tag

type BigNumber

type BigNumber big.Int

func MakeBigNumber

func MakeBigNumber(s string) (*BigNumber, error)

func (*BigNumber) Equal

func (b *BigNumber) Equal(v Value) bool

func (*BigNumber) Marshal

func (b *BigNumber) Marshal(w io.Writer) error

func (*BigNumber) String

func (b *BigNumber) String() string

func (*BigNumber) Tag

func (*BigNumber) Tag() Tag

type Boolean

type Boolean bool

func (Boolean) Bool

func (b Boolean) Bool() bool

func (Boolean) Equal

func (b Boolean) Equal(v Value) bool

func (Boolean) Marshal

func (b Boolean) Marshal(w io.Writer) error

func (Boolean) String

func (b Boolean) String() string

func (Boolean) Tag

func (Boolean) Tag() Tag

type Bulk

type Bulk interface {
	Value
	// contains filtered or unexported methods
}

type BulkError

type BulkError struct {
	// contains filtered or unexported fields
}

func MakeBulkError

func MakeBulkError(s string) *BulkError

func (*BulkError) Equal

func (e *BulkError) Equal(v Value) bool

func (BulkError) Error

func (e BulkError) Error() string

func (*BulkError) Marshal

func (e *BulkError) Marshal(w io.Writer) error

func (BulkError) Prefix

func (e BulkError) Prefix() string

func (BulkError) String

func (e BulkError) String() string

func (*BulkError) Tag

func (*BulkError) Tag() Tag

type BulkString

type BulkString string

func (BulkString) Equal

func (s BulkString) Equal(v Value) bool

func (BulkString) Marshal

func (s BulkString) Marshal(w io.Writer) error

func (BulkString) String

func (s BulkString) String() string

func (BulkString) Tag

func (BulkString) Tag() Tag

type Collection

type Collection interface {
	ForEach(func(Value) error) error
	Contains(Value) bool
	Elements() Values
}

type Counted

type Counted interface {
	Value
	Count() int
}

Counted represents a RESP value that has a count of elements

type Double

type Double float64

func (Double) Equal

func (d Double) Equal(v Value) bool

func (Double) Marshal

func (d Double) Marshal(w io.Writer) error

func (Double) String

func (d Double) String() string

func (Double) Tag

func (Double) Tag() Tag

type Error

type Error interface {
	Value

	Prefix() string
	fmt.Stringer
	error
	// contains filtered or unexported methods
}

func MakeError

func MakeError(s string, args ...any) Error

MakeError creates an Error from a string and optional arguments. If the resulting string contains a CR/LF sequence, a BulkError will be created, otherwise a SimpleError will be created.

type Hasher

type Hasher interface {
	Value
	Hash() uint64
}

type Integer

type Integer int64

func (Integer) Equal

func (i Integer) Equal(v Value) bool

func (Integer) Marshal

func (i Integer) Marshal(w io.Writer) error

func (Integer) String

func (i Integer) String() string

func (Integer) Tag

func (Integer) Tag() Tag

type MakeMapKey

type MakeMapKey interface {
	comparable
	Value
}

type Map

type Map struct {
	// contains filtered or unexported fields
}

func MakeMap

func MakeMap[K MakeMapKey, V Value](m map[K]V) *Map

func MakeMapFromPairs

func MakeMapFromPairs(pairs ...[2]Value) *Map

func (*Map) Count

func (m *Map) Count() int

func (*Map) Equal

func (m *Map) Equal(v Value) bool

func (*Map) ForEach

func (m *Map) ForEach(fn func(Value, Value) error) error

func (*Map) Get

func (m *Map) Get(key Value) (Value, bool)

func (*Map) Hash

func (m *Map) Hash() uint64

func (*Map) Marshal

func (m *Map) Marshal(w io.Writer) error

func (*Map) Tag

func (*Map) Tag() Tag

type Null

type Null struct{}

func (Null) Equal

func (Null) Equal(v Value) bool

func (Null) Marshal

func (n Null) Marshal(w io.Writer) error

func (Null) String

func (Null) String() string

func (Null) Tag

func (Null) Tag() Tag

type Push

type Push struct {
	Values
	// contains filtered or unexported fields
}

func MakePush

func MakePush(v ...Value) *Push

func (*Push) Equal

func (p *Push) Equal(v Value) bool

func (*Push) Hash

func (p *Push) Hash() uint64

func (*Push) Marshal

func (p *Push) Marshal(w io.Writer) error

func (*Push) Tag

func (*Push) Tag() Tag

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func NewReader

func NewReader(r *bufio.Reader) *Reader

NewReader creates a new RESP Reader

func (*Reader) Next

func (r *Reader) Next() (Value, error)

Next returns the next parsed value from the RESP readerFunc, or an error

type Set

type Set struct {
	// contains filtered or unexported fields
}

func MakeSet

func MakeSet(v ...Value) *Set

func (*Set) Contains

func (s *Set) Contains(v Value) bool

func (*Set) Count

func (s *Set) Count() int

func (*Set) Elements

func (s *Set) Elements() Values

func (*Set) Equal

func (s *Set) Equal(v Value) bool

func (*Set) ForEach

func (s *Set) ForEach(fn func(Value) error) error

func (*Set) Hash

func (s *Set) Hash() uint64

func (*Set) Marshal

func (s *Set) Marshal(w io.Writer) error

func (*Set) Tag

func (*Set) Tag() Tag

type Simple

type Simple interface {
	Value
	// contains filtered or unexported methods
}

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) Error

func (e SimpleError) Error() string

func (*SimpleError) Marshal

func (e *SimpleError) Marshal(w io.Writer) error

func (SimpleError) Prefix

func (e SimpleError) Prefix() string

func (SimpleError) String

func (e SimpleError) String() string

func (*SimpleError) Tag

func (*SimpleError) Tag() Tag

type SimpleString

type SimpleString string

func (SimpleString) Equal

func (s SimpleString) Equal(v Value) bool

func (SimpleString) Marshal

func (s SimpleString) Marshal(w io.Writer) error

func (SimpleString) String

func (s SimpleString) String() string

func (SimpleString) Tag

func (SimpleString) Tag() Tag

type String

type String interface {
	Value

	fmt.Stringer
	// contains filtered or unexported methods
}

func MakeString

func MakeString(s string) String

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
	SetTag            Tag = '~' // data
	PushTag           Tag = '>' // push
)

func (Tag) String

func (i Tag) String() string

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

type Values

type Values []Value

func (Values) Contains

func (v Values) Contains(e Value) bool

func (Values) Count

func (v Values) Count() int

func (Values) Elements

func (v Values) Elements() Values

func (Values) Equal

func (v Values) Equal(other Values) bool

func (Values) ForEach

func (v Values) ForEach(fn func(Value) error) error

func (Values) Hash

func (v Values) Hash() uint64

func (Values) Sort

func (v Values) Sort() Values

func (Values) SortWith

func (v Values) SortWith(cmp func(Value, Value) int) Values

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) Marshal

func (s *VerbatimString) Marshal(w io.Writer) error

func (*VerbatimString) String

func (s *VerbatimString) String() string

func (*VerbatimString) Tag

func (*VerbatimString) Tag() Tag

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL