update codec to allow reuse buffers
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -4,9 +4,19 @@ import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"go.unistack.org/micro/v3/broker"
|
||||
"go.unistack.org/micro/v3/codec"
|
||||
)
|
||||
|
||||
func TestRawMessage(t *testing.T) {
|
||||
b := &broker.Message{}
|
||||
buf, err := NewCodec().Marshal(b)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
t.Logf("%s", buf)
|
||||
}
|
||||
|
||||
func TestFrame(t *testing.T) {
|
||||
s := &codec.Frame{Data: []byte("test")}
|
||||
|
||||
@@ -28,7 +38,7 @@ func TestFrameFlatten(t *testing.T) {
|
||||
Name: &codec.Frame{Data: []byte("test")},
|
||||
}
|
||||
|
||||
buf, err := NewCodec().Marshal(s)
|
||||
buf, err := NewCodec(codec.Flatten(true)).Marshal(s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -44,13 +54,13 @@ func TestStructByTag(t *testing.T) {
|
||||
|
||||
val := &Str{Name: []string{"first", "second"}}
|
||||
|
||||
c := NewCodec()
|
||||
c := NewCodec(codec.Flatten(true))
|
||||
buf, err := c.Marshal(val)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(buf, []byte(`["first","second"]`)) {
|
||||
t.Fatalf("invalid marshal: %v != %v", buf, []byte(`["first","second"]`))
|
||||
t.Fatalf("invalid marshal: %s != %s", buf, []byte(`["first","second"]`))
|
||||
}
|
||||
|
||||
err = c.Unmarshal([]byte(`["1","2"]`), val)
|
||||
@@ -62,15 +72,3 @@ func TestStructByTag(t *testing.T) {
|
||||
t.Fatalf("invalid unmarshal: %v", val)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadBody(t *testing.T) {
|
||||
s := &struct {
|
||||
Name string
|
||||
}{}
|
||||
c := NewCodec()
|
||||
b := bytes.NewReader(nil)
|
||||
err := c.ReadBody(b, s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user