From fb6dff1267d2376aa957a0ecfa56aca4f59ea9cd Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Mon, 4 Aug 2014 21:01:33 +0000 Subject: [PATCH] remove a few unecessary conversions and trims --- values.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/values.go b/values.go index 75ab46e..795e8b7 100644 --- a/values.go +++ b/values.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "strconv" - "strings" ) var ( @@ -48,6 +47,8 @@ func readValue(r io.Reader) (value, error) { return readError(line[1:]) case start_integer: return readInteger(line[1:]) + case start_bulkstring: + return readBulkString(line[1:], r) default: return nil, fmt.Errorf("unable to read redis protocol value: illegal start character: %c", line[0]) } @@ -58,7 +59,7 @@ func readValue(r io.Reader) (value, error) { type String string func readString(b []byte) (value, error) { - return String(strings.Trim(string(b), "\r\n")), nil + return String(b), nil } // ------------------------------------------------------------------------------ @@ -66,7 +67,7 @@ func readString(b []byte) (value, error) { type Error string func readError(b []byte) (value, error) { - return Error(strings.Trim(string(b), "\r\n")), nil + return Error(b), nil } // ------------------------------------------------------------------------------ @@ -74,9 +75,17 @@ func readError(b []byte) (value, error) { type Integer int64 func readInteger(b []byte) (value, error) { - i, err := strconv.ParseInt(strings.Trim(string(b), "\r\n"), 10, 64) + i, err := strconv.ParseInt(string(b), 10, 64) if err != nil { return nil, fmt.Errorf("unable to read integer in redis protocol format: %v", err) } return Integer(i), nil } + +// ----------------------------------------------------------------------------------------- + +type BulkString string + +func readBulkString(prefix []byte, r io.Reader) (value, error) { + return nil, nil +}