2018-12-18 11:17:57 +03:00
|
|
|
package pingtunnel
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-10-22 16:04:25 +03:00
|
|
|
"github.com/golang/protobuf/proto"
|
2018-12-18 11:17:57 +03:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test0001(test *testing.T) {
|
|
|
|
|
2019-10-22 16:04:25 +03:00
|
|
|
my := &MyMsg{}
|
|
|
|
my.Id = "12345"
|
|
|
|
my.Target = "111:11"
|
|
|
|
my.Type = 12
|
2018-12-18 11:17:57 +03:00
|
|
|
my.Data = make([]byte, 3)
|
2019-10-22 16:04:25 +03:00
|
|
|
dst, _ := proto.Marshal(my)
|
2018-12-18 11:17:57 +03:00
|
|
|
fmt.Println("dst = ", dst)
|
|
|
|
|
2019-10-22 16:04:25 +03:00
|
|
|
my1 := &MyMsg{}
|
|
|
|
proto.Unmarshal(dst, my1)
|
2018-12-18 11:17:57 +03:00
|
|
|
fmt.Println("my1 = ", my1)
|
|
|
|
|
2019-10-22 16:04:25 +03:00
|
|
|
proto.Unmarshal(dst[0:4], my1)
|
2018-12-18 11:17:57 +03:00
|
|
|
fmt.Println("my1 = ", my1)
|
|
|
|
}
|