Hi, I have a question about the design concern about the conn.WriteAny function.
If I use the conn.WriteInt and pass a int parameter to it, it will write a integer response to the client.
// WriteInt64 writes a 64-bit signed integer to the client.
func (w *Writer) WriteInt64(num int64) {
if w.err != nil {
return
}
w.b = AppendInt(w.b, num)
}
However, if I use the conn.WriteAny and pass the same parameter to it, the function will write a string format of integer response which are quoted with a "" to the client.
func AppendAny(b []byte, v interface{}) []byte {
switch v := v.(type) {
case SimpleString:
b = AppendString(b, string(v))
case SimpleInt:
b = AppendInt(b, int64(v))
case SimpleError:
b = AppendError(b, v.Error())
case nil:
b = AppendNull(b)
case error:
b = AppendError(b, prefixERRIfNeeded(v.Error()))
case string:
b = AppendBulkString(b, v)
case []byte:
b = AppendBulk(b, v)
case bool:
if v {
b = AppendBulkString(b, "1")
} else {
b = AppendBulkString(b, "0")
}
case int:
b = AppendBulkInt(b, int64(v))
case int8:
b = AppendBulkInt(b, int64(v))
case int16:
b = AppendBulkInt(b, int64(v))
case int32:
b = AppendBulkInt(b, int64(v))
case int64:
b = AppendBulkInt(b, int64(v))
......
}
}
Can you give me any ideas about the design principles here?
Hi, I have a question about the design concern about the conn.WriteAny function.
If I use the conn.WriteInt and pass a int parameter to it, it will write a integer response to the client.
However, if I use the conn.WriteAny and pass the same parameter to it, the function will write a string format of integer response which are quoted with a "" to the client.
Can you give me any ideas about the design principles here?