@@ -29,8 +29,7 @@ type mockEncoder struct {
}
func (m mockEncoder) encode(pe packetEncoder) error {
- fmt.Println(m.bytes)
- pe.putBytes(m.bytes)
+ pe.putRawBytes(m.bytes)
return nil
@@ -13,6 +13,7 @@ type packetEncoder interface {
// Collections
putBytes(in []byte) error
+ putRawBytes(in []byte) error
putString(in string) error
putInt32Array(in []int32) error
putInt64Array(in []int64) error
@@ -49,6 +49,14 @@ func (pe *prepEncoder) putBytes(in []byte) error {
+func (pe *prepEncoder) putRawBytes(in []byte) error {
+ if len(in) > math.MaxInt32 {
+ return EncodingError
+ }
+ pe.length += len(in)
+ return nil
+}
+
func (pe *prepEncoder) putString(in string) error {
pe.length += 2
if len(in) > math.MaxInt16 {
@@ -37,6 +37,12 @@ func (re *realEncoder) putArrayLength(in int) error {
// collection
+func (re *realEncoder) putRawBytes(in []byte) error {
+ copy(re.raw[re.off:], in)
+ re.off += len(in)
func (re *realEncoder) putBytes(in []byte) error {
if in == nil {
re.putInt32(-1)