mirror of https://github.com/tidwall/redcon.git
Added convenience functions
This commit is contained in:
parent
768b712a98
commit
428ef2271a
19
resp.go
19
resp.go
|
@ -20,7 +20,6 @@ const (
|
|||
Error = '-'
|
||||
)
|
||||
|
||||
// RESP ...
|
||||
type RESP struct {
|
||||
Type Type
|
||||
Raw []byte
|
||||
|
@ -40,6 +39,24 @@ func (r *RESP) ForEach(iter func(resp RESP) bool) {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *RESP) Bytes() []byte {
|
||||
return r.Data
|
||||
}
|
||||
|
||||
func (r *RESP) String() string {
|
||||
return string(r.Data)
|
||||
}
|
||||
|
||||
func (r *RESP) Int() int64 {
|
||||
x, _ := strconv.ParseInt(r.String(), 10, 64)
|
||||
return x
|
||||
}
|
||||
|
||||
func (r *RESP) Float() float64 {
|
||||
x, _ := strconv.ParseFloat(r.String(), 10)
|
||||
return x
|
||||
}
|
||||
|
||||
// ReadNextRESP returns the next resp in b and returns the number of bytes the
|
||||
// took up the result.
|
||||
func ReadNextRESP(b []byte) (n int, resp RESP) {
|
||||
|
|
Loading…
Reference in New Issue