func (br *BulkResp) Bytes() []byte { if br.Rtype != BulkType { panic(RespTypeError) } if br.Empty { return EmptyBulk } b := new(bytes.Buffer) b.WriteByte(BulkSep) // b.Write(util.Iu32tob2(len(br.Args[0]))) util.WriteLength(b, len(br.Args[0])) b.Write(CRLF) b.Write(br.Args[0]) b.Write(CRLF) return b.Bytes() }
func (ar *ArrayResp) Encode(w *bufio.Writer) error { if ar.Rtype != ArrayType { panic(RespTypeError) } // var b bytes.Buffer b := bPool.Get().(*bytes.Buffer) b.Reset() defer bPool.Put(b) b.WriteByte(ArrSep) // b.Write(util.Iu32tob2(len(ar.Args))) util.WriteLength(b, len(ar.Args)) b.Write(CRLF) for _, arg := range ar.Args { b.Write(arg.Bytes()) } // return b.Bytes() err := WriteRawByte(w, b.Bytes()) return err }
func (br *BulkResp) Encode(w *bufio.Writer) error { if br.Rtype != BulkType { panic(RespTypeError) } if br.Empty { return WriteRawByte(w, EmptyBulk) } // var b bytes.Buffer b := bPool.Get().(*bytes.Buffer) b.Reset() defer bPool.Put(b) b.WriteByte(BulkSep) // b.Write(util.Iu32tob2(len(br.Args[0]))) util.WriteLength(b, len(br.Args[0])) b.Write(CRLF) b.Write(br.Args[0]) b.Write(CRLF) err := WriteRawByte(w, b.Bytes()) return err }