From 428ef2271a92eb2c90429fdd3b751f19adacb074 Mon Sep 17 00:00:00 2001 From: tidwall Date: Wed, 27 Jul 2022 11:50:30 -0700 Subject: [PATCH] Added convenience functions --- resp.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/resp.go b/resp.go index 4f58dad..07700bf 100644 --- a/resp.go +++ b/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) {