resp icon indicating copy to clipboard operation
resp copied to clipboard

Fix missing processing in Message marshal

Open amyangfei opened this issue 10 years ago • 2 comments

  1. []*Message type is missing in Encoder writeEncoded processing.
  2. Support marshal nil object from a Message directly.

amyangfei avatar Dec 05 '15 16:12 amyangfei

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?

xiam avatar Dec 08 '15 01:12 xiam

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)                                                                      
}

amyangfei avatar Dec 08 '15 05:12 amyangfei