Files
bl/common/core/info/login/CommendSvrInfo_test.go

48 lines
1.2 KiB
Go
Raw Normal View History

2025-06-24 22:09:05 +08:00
package login
import (
"bytes"
"encoding/hex"
"fmt"
"testing"
"github.com/gogf/gf/v2/frame/g"
"github.com/lunixbochs/struc"
)
func TestNewCommendSvrInfo(t *testing.T) {
ret := NewCommendSvrInfo()
lofin := NewServerInfo()
lofin.OnlineID = 1
lofin.UserCnt = 77
lofin.IP = "127.0.0.1"
lofin.Port = 27777
lofin.Friends = 1
ret.ServerList = append(ret.ServerList, *lofin)
// bytt := bytearray.CreateByteArray()
// bytt.WriteUInt32(100)
// bytt.WriteUInt32(0)
// //ret.ServerList = append(ret.ServerList, *lofin)
var trr bytes.Buffer
// err := struc.Pack(&trr, lofin)
// bytt.WriteUInt32(1) //长度
// bytt.Write(trr.Bytes())
// bytt.WriteUInt32(1)
// //err:=Println(trr.Bytes())
/// 00 00 00 64 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 4d 31 32 37 2e 30 2e 30 2e 31 00 00 00 00 00 00 00 6c 81 00 00 00 01 00 00 00 00
err := struc.Pack(&trr, ret)
fmt.Println(err)
fmt.Println(trr.Bytes())
g.Dump(ret)
fmt.Println("000000640000000000000001000000010000004d3132372e302e302e31000000000000006c810000000100000000")
fmt.Println("000000640000000000000001000000010000004d3132372e302e302e31000000000000006c810000000100000000")
fmt.Println(hex.EncodeToString(trr.Bytes()))
}