Browse Source

Fixed remaining test.

Burke Libbey 12 years ago
parent
commit
2f5cf8fd16
4 changed files with 16 additions and 2 deletions
  1. 1 2
      broker_test.go
  2. 1 0
      packet_encoder.go
  3. 8 0
      prep_encoder.go
  4. 6 0
      real_encoder.go

+ 1 - 2
broker_test.go

@@ -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
 }
 

+ 1 - 0
packet_encoder.go

@@ -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

+ 8 - 0
prep_encoder.go

@@ -49,6 +49,14 @@ func (pe *prepEncoder) putBytes(in []byte) error {
 	return nil
 }
 
+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 {

+ 6 - 0
real_encoder.go

@@ -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)
+	return nil
+}
+
 func (re *realEncoder) putBytes(in []byte) error {
 	if in == nil {
 		re.putInt32(-1)