forked from d-o-n-u-t-s/lz4msgpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlz4msgpack_test.go
More file actions
48 lines (41 loc) · 1.12 KB
/
lz4msgpack_test.go
File metadata and controls
48 lines (41 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package lz4msgpack_test
import (
"reflect"
"testing"
"github.com/shamaton/lz4msgpack"
"github.com/shamaton/msgpack"
)
type marshaller func(v interface{}) ([]byte, error)
type unMarshaller func([]byte, interface{}) error
func Test(t *testing.T) {
type Data struct {
A int
B float32
C []string
}
data := Data{
A: 4578234323,
B: 1.46437485,
C: []string{"Hello World", "Hello World", "Hello World", "Hello World", "Hello World"},
}
t.Log(data)
tester := func(name string, m marshaller, u unMarshaller) {
b, err := m(&data)
if err != nil {
t.Fatal("marshal failed", err)
}
t.Logf("%s: %d", name, len(b))
var data1 Data
err = u(b, &data1)
if err != nil {
t.Fatal("unmarshal failed", err)
}
if !reflect.DeepEqual(data, data1) {
t.Fatal(name + " Error")
}
}
tester(" msgpack.Marshal", msgpack.Encode, msgpack.Decode)
tester(" msgpack.MarshalAsArray", msgpack.EncodeStructAsArray, msgpack.DecodeStructAsArray)
tester(" lz4msgpack.Marshal", lz4msgpack.Marshal, lz4msgpack.Unmarshal)
tester("lz4msgpack.MarshalAsArray", lz4msgpack.MarshalAsArray, lz4msgpack.UnmarshalAsArray)
}