package resp2 - github.com/mediocregopher/radix/v4/resp/resp2 - godocs.io
import "github.com/mediocregopher/radix/v4/resp/resp2"
Package resp2 implements the original redis RESP protocol, a plaintext protocol which is also binary safe. RESP has been supplanted by RESP3, implemented in the resp3 package.
See https://redis.io/topics/protocol for more details on the protocol.
Variables
var (
SimpleStringPrefix = []byte{'+'}
ErrorPrefix = []byte{'-'}
IntPrefix = []byte{':'}
BulkStringPrefix = []byte{'$'}
ArrayPrefix = []byte{'*'}
)
Enumeration of each of RESP's message types, each denoted by the prefix which is prepended to messages of that type.
In order to determine the type of a message which is being written to a *bufio.Reader, without actually consuming it, one can use the Peek method and compare it against these values.
Types
type Any
type Any struct {
I interface{}
// If true then the MarshalRESP method will marshal all non-array types as
// bulk strings. This primarily effects integers and errors.
MarshalBulkString bool
// If true then no array headers will be sent when MarshalRESP is called.
// For I values which are non-arrays this means no behavior change. For
// arrays and embedded arrays it means only the array elements will be
// written, and an ArrayHeader must have been manually marshalled
// beforehand.
MarshalNoArrayHeaders bool
}
Any represents any primitive go type, such as integers, floats, strings, bools, etc... It also includes encoding.Text(Un)Marshalers and encoding.(Un)BinaryMarshalers. It will _not_ marshal resp.Marshalers.
Most things will be treated as bulk strings, except for those that have their own corresponding type in the RESP protocol (e.g. ints). strings and []bytes will always be encoded as bulk strings, never simple strings.
Arrays and slices will be treated as RESP arrays, and their values will be treated as if also wrapped in an Any struct. Maps will be similarly treated, but they will be flattened into arrays of their alternating keys/values first.
When using UnmarshalRESP the value of I must be a pointer or nil. If it is nil then the RESP value will be read and discarded.
If an error type is read in the UnmarshalRESP method then a resp2.Error will be returned with that error, and the value of I won't be touched.
func (Any) MarshalRESP
func (a Any) MarshalRESP(w io.Writer) error
MarshalRESP implements the Marshaler method
func (Any) NumElems
func (a Any) NumElems() int
NumElems returns the number of non-array elements which would be marshalled based on I. For example:
Any{I: "foo"}.NumElems() == 1
Any{I: []string{}}.NumElems() == 0
Any{I: []string{"foo"}}.NumElems() == 1
Any{I: []string{"foo", "bar"}}.NumElems() == 2
Any{I: [][]string{{"foo"}, {"bar", "baz"}, {}}}.NumElems() == 3
func (Any) UnmarshalRESP
func (a Any) UnmarshalRESP(br *bufio.Reader) error
UnmarshalRESP implements the Unmarshaler method
type Array
type Array struct {
A []resp.Marshaler
}
Array represents an array of RESP elements which will be marshaled as a RESP array. If A is Nil then a Nil RESP will be marshaled.
func (Array) MarshalRESP
func (a Array) MarshalRESP(w io.Writer) error
MarshalRESP implements the Marshaler method
type ArrayHeader
type ArrayHeader struct {
N int
}
ArrayHeader represents the header sent preceding array elements in the RESP protocol. It does not actually encompass any elements itself, it only declares how many elements will come after it.
An N of -1 may also be used to indicate a nil response, as per the RESP spec
func (ArrayHeader) MarshalRESP
func (ah ArrayHeader) MarshalRESP(w io.Writer) error
MarshalRESP implements the Marshaler method
func (*ArrayHeader) UnmarshalRESP
func (ah *ArrayHeader) UnmarshalRESP(br *bufio.Reader) error
UnmarshalRESP implements the Unmarshaler method
type BulkReader
type BulkReader struct {
LR resp.LenReader
}
BulkReader is like BulkString, but it only supports marshalling and will use the given LenReader to do so. If LR is nil then the nil bulk string RESP will be written
func (BulkReader) MarshalRESP
func (b BulkReader) MarshalRESP(w io.Writer) error
MarshalRESP implements the Marshaler method
type BulkString
type BulkString struct {
S string
}
BulkString represents the bulk string type in the RESP protocol using a go string.
func (BulkString) MarshalRESP
func (b BulkString) MarshalRESP(w io.Writer) error
MarshalRESP implements the Marshaler method
func (*BulkString) UnmarshalRESP
func (b *BulkString) UnmarshalRESP(br *bufio.Reader) error
UnmarshalRESP implements the Unmarshaler method. This treats a Nil bulk string message as empty string.
type BulkStringBytes
type BulkStringBytes struct {
B []byte
// If true then this won't marshal the nil RESP value when B is nil, it will
// marshal as an empty string instead
MarshalNotNil bool
}
BulkStringBytes represents the bulk string type in the RESP protocol using a go byte slice. A B value of nil indicates the nil bulk string message, versus a B value of []byte{} which indicates a bulk string of length 0.
func (BulkStringBytes) MarshalRESP
func (b BulkStringBytes) MarshalRESP(w io.Writer) error
MarshalRESP implements the Marshaler method
func (*BulkStringBytes) UnmarshalRESP
func (b *BulkStringBytes) UnmarshalRESP(br *bufio.Reader) error
UnmarshalRESP implements the Unmarshaler method
type Error
type Error struct {
E error
}
Error represents an error type in the RESP protocol. Note that this only represents an actual error message being read/written on the stream, it is separate from network or parsing errors. An E value of nil is equivalent to an empty error string
func (Error) Error
func (e Error) Error() string
func (Error) MarshalRESP
func (e Error) MarshalRESP(w io.Writer) error
MarshalRESP implements the Marshaler method
func (*Error) UnmarshalRESP
func (e *Error) UnmarshalRESP(br *bufio.Reader) error
UnmarshalRESP implements the Unmarshaler method
type Int
type Int struct {
I int64
}
Int represents an int type in the RESP protocol
func (Int) MarshalRESP
func (i Int) MarshalRESP(w io.Writer) error
MarshalRESP implements the Marshaler method
func (*Int) UnmarshalRESP
func (i *Int) UnmarshalRESP(br *bufio.Reader) error
UnmarshalRESP implements the Unmarshaler method
type RawMessage
type RawMessage []byte
RawMessage is a Marshaler/Unmarshaler which will capture the exact raw bytes of a RESP message. When Marshaling the exact bytes of the RawMessage will be written as-is. When Unmarshaling the bytes of a single RESP message will be read into the RawMessage's bytes.
func (RawMessage) IsEmptyArray
func (rm RawMessage) IsEmptyArray() bool
IsEmptyArray returns true if the contents of RawMessage is empty array value.
func (RawMessage) IsNil
func (rm RawMessage) IsNil() bool
IsNil returns true if the contents of RawMessage are one of the nil values.
func (RawMessage) MarshalRESP
func (rm RawMessage) MarshalRESP(w io.Writer) error
MarshalRESP implements the Marshaler method
func (RawMessage) UnmarshalInto
func (rm RawMessage) UnmarshalInto(u resp.Unmarshaler) error
UnmarshalInto is a shortcut for wrapping this RawMessage in a *bufio.Reader and passing that into the given Unmarshaler's UnmarshalRESP method. Any error from calling UnmarshalRESP is returned, and the RawMessage is unaffected in all cases.
func (*RawMessage) UnmarshalRESP
func (rm *RawMessage) UnmarshalRESP(br *bufio.Reader) error
UnmarshalRESP implements the Unmarshaler method
type SimpleString
type SimpleString struct {
S string
}
SimpleString represents the simple string type in the RESP protocol
func (SimpleString) MarshalRESP
func (ss SimpleString) MarshalRESP(w io.Writer) error
MarshalRESP implements the Marshaler method
func (*SimpleString) UnmarshalRESP
func (ss *SimpleString) UnmarshalRESP(br *bufio.Reader) error
UnmarshalRESP implements the Unmarshaler method
Details
Version: v4.0.0-beta.0- Published: Oct 4, 2020
Imports: 11 packages
- Last checked: 4 minutes ago
Search
Response: 20 (Success), text/gemini
| Original URL | gemini://godocs.io/github.com/mediocregopher/radix/v4/res... |
|---|---|
| Status Code | 20 (Success) |
| Content-Type | text/gemini; charset=utf-8 |