2
0

Replace MarshalBinary with Encode

This new approach can avoid allocations.
This commit is contained in:
Jack Christensen
2017-05-26 17:00:44 -05:00
parent b1934ad4c2
commit d6312305ae
35 changed files with 277 additions and 285 deletions
+4 -4
View File
@@ -103,11 +103,11 @@ func (dst *ErrorResponse) Decode(src []byte) error {
return nil
}
func (src *ErrorResponse) MarshalBinary() ([]byte, error) {
return src.marshalBinary('E')
func (src *ErrorResponse) Encode(dst []byte) []byte {
return append(dst, src.marshalBinary('E')...)
}
func (src *ErrorResponse) marshalBinary(typeByte byte) ([]byte, error) {
func (src *ErrorResponse) marshalBinary(typeByte byte) []byte {
var bigEndian BigEndianBuf
buf := &bytes.Buffer{}
@@ -193,5 +193,5 @@ func (src *ErrorResponse) marshalBinary(typeByte byte) ([]byte, error) {
binary.BigEndian.PutUint32(buf.Bytes()[1:5], uint32(buf.Len()-1))
return buf.Bytes(), nil
return buf.Bytes()
}