github.com/volts-dev/volts@v0.0.0-20240120094013-5e9c65924106/codec/msgpack_test.go (about)

     1  package codec
     2  
     3  import (
     4  	"errors"
     5  	"log"
     6  	"testing"
     7  )
     8  
     9  func TestMg(t *testing.T) {
    10  	type Test1 struct {
    11  		Id   int64
    12  		Name string
    13  		//Time string
    14  	}
    15  	type Test2 struct {
    16  		Id   int64
    17  		Name string
    18  		Test Test1
    19  		//Time time.Time
    20  	}
    21  	coder := new(msgpackCodec)
    22  	buf, err := coder.Encode(&Test2{Id: 1234541341234123412, Name: "adc", Test: Test1{Id: 1234541341234123412, Name: errors.New("403 Forbidden").Error()}}) //"2016-01-02"
    23  	if err != nil {
    24  
    25  	}
    26  
    27  	//buf = []byte(`{"id":1234541341234123412,"Time": "2014-04-11"}`)
    28  	var test *Test2
    29  	err = coder.Decode(buf, &test)
    30  	if err != nil {
    31  		t.Fatal(err)
    32  	}
    33  	log.Print(test)
    34  }