This commit is contained in:
esrrhs 2018-12-18 16:17:57 +08:00
parent ae1cb0762b
commit 38572c7976
2 changed files with 29 additions and 0 deletions

View File

@ -67,6 +67,7 @@ func (p *MyMsg) MarshalString(s string) []byte {
// Marshal implements the Marshal method of MessageBody interface. // Marshal implements the Marshal method of MessageBody interface.
func (p *MyMsg) Unmarshal(b []byte) error { func (p *MyMsg) Unmarshal(b []byte) error {
defer func() { defer func() {
recover()
}() }()
p.TYPE = binary.BigEndian.Uint32(b[:4]) p.TYPE = binary.BigEndian.Uint32(b[:4])

28
server_test.go Normal file
View File

@ -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)
}