|
|
|
@ -125,7 +125,11 @@ func readString(b []byte) (value, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s String) Write(w io.Writer) (int, error) {
|
|
|
|
|
return fmt.Fprintf(w, "+%s\r\n", s)
|
|
|
|
|
w.Write([]byte{'+'})
|
|
|
|
|
w.Write([]byte(s))
|
|
|
|
|
w.Write([]byte{'\r', '\n'})
|
|
|
|
|
return 0, nil
|
|
|
|
|
// return fmt.Fprintf(w, "+%s\r\n", s)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
@ -137,7 +141,11 @@ func readError(b []byte) (value, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e Error) Write(w io.Writer) (int, error) {
|
|
|
|
|
return fmt.Fprintf(w, "-%s\r\n")
|
|
|
|
|
w.Write([]byte{'-'})
|
|
|
|
|
w.Write([]byte(e))
|
|
|
|
|
w.Write([]byte{'\r', '\n'})
|
|
|
|
|
return 0, nil
|
|
|
|
|
// return fmt.Fprintf(w, "-%s\r\n")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
@ -153,7 +161,11 @@ func readInteger(b []byte) (value, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (i Integer) Write(w io.Writer) (int, error) {
|
|
|
|
|
return fmt.Fprintf(w, ":%d\r\n", i)
|
|
|
|
|
w.Write([]byte{':'})
|
|
|
|
|
w.Write([]byte(strconv.Itoa(int(i))))
|
|
|
|
|
w.Write([]byte{'\r', '\n'})
|
|
|
|
|
return 0, nil
|
|
|
|
|
// return fmt.Fprintf(w, ":%d\r\n", i)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
@ -198,7 +210,13 @@ func readBulkString(prefix []byte, r io.Reader) (value, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s BulkString) Write(w io.Writer) (int, error) {
|
|
|
|
|
return fmt.Fprintf(w, "$%d\r\n%s\r\n", len(s), s)
|
|
|
|
|
w.Write([]byte{'$'})
|
|
|
|
|
w.Write([]byte(strconv.Itoa(len(s))))
|
|
|
|
|
w.Write([]byte{'\r', '\n'})
|
|
|
|
|
w.Write([]byte(s))
|
|
|
|
|
w.Write([]byte{'\r', '\n'})
|
|
|
|
|
return 0, nil
|
|
|
|
|
// return fmt.Fprintf(w, "$%d\r\n%s\r\n", len(s), s)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------------------
|
|
|
|
@ -230,21 +248,26 @@ func readArray(prefix []byte, r *bufio.Reader) (value, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a Array) Write(w io.Writer) (int, error) {
|
|
|
|
|
n, err := fmt.Fprintf(w, "*%d\r\n", len(a))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return n, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
nn int
|
|
|
|
|
e error
|
|
|
|
|
)
|
|
|
|
|
w.Write([]byte{'*'})
|
|
|
|
|
w.Write([]byte(strconv.Itoa(len(a))))
|
|
|
|
|
w.Write([]byte{'\r', '\n'})
|
|
|
|
|
// n, err := fmt.Fprintf(w, "*%d\r\n", len(a))
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// return n, err
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// var (
|
|
|
|
|
// nn int
|
|
|
|
|
// e error
|
|
|
|
|
// )
|
|
|
|
|
for i := 0; i < len(a); i++ {
|
|
|
|
|
nn, e = a[i].Write(w)
|
|
|
|
|
n += nn
|
|
|
|
|
if e != nil {
|
|
|
|
|
return n, e
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return n, nil
|
|
|
|
|
a[i].Write(w)
|
|
|
|
|
// nn, e = a[i].Write(w)
|
|
|
|
|
// n += nn
|
|
|
|
|
// if e != nil {
|
|
|
|
|
// return n, e
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
// return n, nil
|
|
|
|
|
return 0, nil
|
|
|
|
|
}
|
|
|
|
|