resp
resp copied to clipboard
Fix missing processing in Message marshal
- []*Message type is missing in Encoder writeEncoded processing.
- Support marshal nil object from a Message directly.
Thanks for your contribution @amyangfei, this is a complicated topic since redis has two representations for nil. I am concerned about the implications of trying to support both, what's the specific scenario you're trying to fix?
Hi @xiam , my use scenario is that there is a stream of data in the RESP format and I use the Unmarshal method provided by resp library to fill the Go value to some Message objects. These Message objects may be used later with Marshal function. code snippet likes following
var m *resp.Message = new(resp.Message)
buf := []byte("$-1\r\n")
if err := resp.Unmarshal(buf, m); err != nil {
panic(err)
}
// wants to get buf equals to "$-1\r\n" here
if buf, err := resp.Marshal(m); err != nil {
panic(err)
}
buf = []byte("*-1\r\n")
if err := resp.Unmarshal(buf, m); err != nil {
panic(err)
}
// wants to get buf equals to "*-1\r\n" here
if buf, err := resp.Marshal(m); err != nil {
panic(err)
}