Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/binary"
"errors"

fastJSON "github.com/segmentio/encoding/json"
)

Expand Down Expand Up @@ -299,11 +300,6 @@ func (e *JSONReplyEncoder) Encode(r *Reply) ([]byte, error) {
return result, nil
}

//func (e *JSONReplyEncoder) EncodeNoCopy(r *Reply, _ []byte) ([]byte, error) {
// // No copy is not supported for JSON encoding. Just use Encode method, ignore pre-allocated buffer.
// return e.Encode(r)
//}

// ProtobufReplyEncoder ...
type ProtobufReplyEncoder struct{}

Expand All @@ -317,21 +313,12 @@ func (e *ProtobufReplyEncoder) Encode(r *Reply) ([]byte, error) {
return r.MarshalVT()
}

//// EncodeNoCopy Reply to bytes without making copy of buffer byte slice.
//func (e *ProtobufReplyEncoder) EncodeNoCopy(r *Reply, buf []byte) ([]byte, error) {
// size := r.SizeVT()
// n, err := r.MarshalToSizedBufferVT(buf[:size])
// if err != nil {
// return nil, err
// }
// return buf[:n], nil
//}

// DataEncoder ...
type DataEncoder interface {
Reset()
Encode([]byte) error
Finish() []byte
FinishNoCopy() []byte
}

// JSONDataEncoder ...
Expand Down Expand Up @@ -369,6 +356,10 @@ func (e *JSONDataEncoder) Finish() []byte {
return dataCopy
}

func (e *JSONDataEncoder) FinishNoCopy() []byte {
return e.buffer.Bytes()
}

// ProtobufDataEncoder ...
type ProtobufDataEncoder struct {
buffer bytes.Buffer
Expand Down Expand Up @@ -401,6 +392,10 @@ func (e *ProtobufDataEncoder) Finish() []byte {
return dataCopy
}

func (e *ProtobufDataEncoder) FinishNoCopy() []byte {
return e.buffer.Bytes()
}

// ResultEncoder ...
type ResultEncoder interface {
EncodeConnectResult(*ConnectResult) ([]byte, error)
Expand Down
Loading