From a11b22fce9d1a409956d1ba0e1b82ed342a42e81 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Thu, 24 Sep 2020 09:06:17 +0300 Subject: [PATCH] Cleanup --- command.go | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/command.go b/command.go index 5451ba2f..5dd55332 100644 --- a/command.go +++ b/command.go @@ -1073,12 +1073,26 @@ func (cmd *XMessageSliceCmd) String() string { } func (cmd *XMessageSliceCmd) readReply(rd *proto.Reader) error { - v, err := rd.ReadArrayReply(xMessageSliceParser) + var err error + cmd.val, err = readXMessageSlice(rd) + return err +} + +func readXMessageSlice(rd *proto.Reader) ([]XMessage, error) { + n, err := rd.ReadArrayLen() if err != nil { - return err + return nil, err } - cmd.val = v.([]XMessage) - return nil + + msgs := make([]XMessage, n) + for i := 0; i < n; i++ { + var err error + msgs[i], err = readXMessage(rd) + if err != nil { + return nil, err + } + } + return msgs, nil } func readXMessage(rd *proto.Reader) (XMessage, error) { @@ -1112,19 +1126,6 @@ func readXMessage(rd *proto.Reader) (XMessage, error) { }, nil } -// xMessageSliceParser implements proto.MultiBulkParse. -func xMessageSliceParser(rd *proto.Reader, n int64) (interface{}, error) { - msgs := make([]XMessage, n) - for i := int64(0); i < n; i++ { - var err error - msgs[i], err = readXMessage(rd) - if err != nil { - return nil, err - } - } - return msgs, nil -} - // stringInterfaceMapParser implements proto.MultiBulkParse. func stringInterfaceMapParser(rd *proto.Reader, n int64) (interface{}, error) { m := make(map[string]interface{}, n/2) @@ -1195,14 +1196,14 @@ func (cmd *XStreamSliceCmd) readReply(rd *proto.Reader) error { return nil, err } - v, err := rd.ReadArrayReply(xMessageSliceParser) + msgs, err := readXMessageSlice(rd) if err != nil { return nil, err } cmd.val[i] = XStream{ Stream: stream, - Messages: v.([]XMessage), + Messages: msgs, } return nil, nil })