Added convenience functions

This commit is contained in:
tidwall 2022-07-27 11:50:30 -07:00
parent 768b712a98
commit 428ef2271a
1 changed files with 18 additions and 1 deletions

19
resp.go
View File

@ -20,7 +20,6 @@ const (
Error = '-' Error = '-'
) )
// RESP ...
type RESP struct { type RESP struct {
Type Type Type Type
Raw []byte 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 // ReadNextRESP returns the next resp in b and returns the number of bytes the
// took up the result. // took up the result.
func ReadNextRESP(b []byte) (n int, resp RESP) { func ReadNextRESP(b []byte) (n int, resp RESP) {