From 38572c79766675e36eee13d41daf2d0b6576a8d3 Mon Sep 17 00:00:00 2001 From: esrrhs Date: Tue, 18 Dec 2018 16:17:57 +0800 Subject: [PATCH] fix --- pingtunnel.go | 1 + server_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 server_test.go diff --git a/pingtunnel.go b/pingtunnel.go index 7de1588..8f54e79 100644 --- a/pingtunnel.go +++ b/pingtunnel.go @@ -67,6 +67,7 @@ func (p *MyMsg) MarshalString(s string) []byte { // Marshal implements the Marshal method of MessageBody interface. func (p *MyMsg) Unmarshal(b []byte) error { defer func() { + recover() }() p.TYPE = binary.BigEndian.Uint32(b[:4]) diff --git a/server_test.go b/server_test.go new file mode 100644 index 0000000..98788c5 --- /dev/null +++ b/server_test.go @@ -0,0 +1,28 @@ +package pingtunnel + +import ( + "fmt" + "github.com/esrrhs/pingtunnel" + "testing" +) + +func Test0001(test *testing.T) { + + my := &pingtunnel.MyMsg{ + } + my.ID = "12345" + my.TARGET = "111:11" + my.TYPE = 12 + my.Data = make([]byte, 3) + dst,_ := my.Marshal(0) + fmt.Println("dst = ", dst) + + + my1 := &pingtunnel.MyMsg{ + } + my1.Unmarshal(dst) + fmt.Println("my1 = ", my1) + + my1.Unmarshal(dst[0:4]) + fmt.Println("my1 = ", my1) +}