Bläddra i källkod

fixed long set/list items, added testcases

Christoph Hack 12 år sedan
förälder
incheckning
a25dee025e
2 ändrade filer med 23 tillägg och 2 borttagningar
  1. 2 2
      marshal.go
  2. 21 0
      marshal_test.go

+ 2 - 2
marshal.go

@@ -785,7 +785,7 @@ func unmarshalList(info *TypeInfo, data []byte, value interface{}) error {
 		if len(data) < 2 {
 			return unmarshalErrorf("unmarshal list: unexpected eof")
 		}
-		n := int(data[0]<<8) | int(data[1])
+		n := int(data[0])<<8 | int(data[1])
 		data = data[2:]
 		if k == reflect.Array {
 			if rv.Len() != n {
@@ -800,7 +800,7 @@ func unmarshalList(info *TypeInfo, data []byte, value interface{}) error {
 			if len(data) < 2 {
 				return unmarshalErrorf("unmarshal list: unexpected eof")
 			}
-			m := int(data[0]<<8) | int(data[1])
+			m := int(data[0])<<8 | int(data[1])
 			data = data[2:]
 			if err := Unmarshal(info.Elem, data[:m], rv.Index(i).Addr().Interface()); err != nil {
 				return err

+ 21 - 0
marshal_test.go

@@ -155,6 +155,27 @@ var marshalTests = []struct {
 		[]byte(nil),
 		map[string]int(nil),
 	},
+	{
+		&TypeInfo{Type: TypeList, Elem: &TypeInfo{Type: TypeVarchar}},
+		bytes.Join([][]byte{
+			[]byte("\x00\x01\xFF\xFF"),
+			bytes.Repeat([]byte("X"), 65535)}, []byte("")),
+		[]string{strings.Repeat("X", 65535)},
+	},
+	{
+		&TypeInfo{Type: TypeMap,
+			Key:  &TypeInfo{Type: TypeVarchar},
+			Elem: &TypeInfo{Type: TypeVarchar},
+		},
+		bytes.Join([][]byte{
+			[]byte("\x00\x01\xFF\xFF"),
+			bytes.Repeat([]byte("X"), 65535),
+			[]byte("\xFF\xFF"),
+			bytes.Repeat([]byte("Y"), 65535)}, []byte("")),
+		map[string]string{
+			strings.Repeat("X", 65535): strings.Repeat("Y", 65535),
+		},
+	},
 }
 
 func TestMarshal(t *testing.T) {