| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package cli
- import (
- "f1-game/internal/pb"
- "fmt"
- "strings"
- "testing"
- "time"
- pomeloClient "github.com/cherry-game/cherry/net/parser/pomelo/client"
- cherrySerializer "github.com/cherry-game/cherry/net/serializer"
- )
- var (
- protobuf = cherrySerializer.NewProtobuf()
- json = cherrySerializer.NewJSON()
- )
- func TestRunRobot(t *testing.T) {
- cli := New(
- pomeloClient.New(
- pomeloClient.WithRequestTimeout(5*time.Second),
- pomeloClient.WithErrorBreak(true),
- ),
- false,
- )
- cli.ConnectToTCP("172.16.124.137:21000")
- msg, err := cli.Request("gate.user.login", &pb.UserLoginRequest{
- Token: "eyJwaWQiOjIxMjYwMDMsIm9wZW5faWQiOiIxMDAwMjI1IiwidHQiOjE2NTQ1ODMyMTQsImhhc2giOiJjY2RkZWI2Y2Q3NTE2MTU1YWM4ZGEzNWUyM2RlMzk1ZSJ9",
- Params: nil,
- })
- fmt.Println(msg, err)
- }
- func TestLoginRequest(t *testing.T) {
- loginRequest := &pb.UserLoginRequest{
- Token: "eyJwaWQiOjIxMjYwMDMsIm9wZW5faWQiOiIxMDAwMjI1IiwidHQiOjE2NTQ1ODMyMTQsImhhc2giOiJjY2RkZWI2Y2Q3NTE2MTU1YWM4ZGEzNWUyM2RlMzk1ZSJ9",
- }
- bytes, _ := protobuf.Marshal(loginRequest)
- fmt.Println(bytes)
- }
- func TestBytes2PB(t *testing.T) {
- bytes := []byte{120, 156, 29, 202, 189, 14, 194, 32, 16, 0, 224, 213, 217, 55, 225, 212, 161, 99, 19, 136, 30,
- 201, 209, 80, 105, 8, 108, 198, 191, 66, 117, 114, 184, 210, 248, 18, 190, 177, 232, 250, 229, 91, 125, 204, 250, 125,
- 45, 154, 79, 222, 166, 46, 227, 76, 57, 48, 73, 122, 225, 179, 225, 232, 119, 183, 191, 167, 234, 178, 101, 202, 40, 48, 113, 186, 28, 126, 87, 129, 113, 86, 116, 146, 10, 57, 91, 255, 56, 158, 225, 94,
- 175, 206, 1, 250, 41, 122, 132, 0, 118, 99, 156, 2, 114, 131, 8, 158, 182, 113, 175, 22, 227, 135, 66, 208, 63, 104, 153,
- 68, 60, 234, 230, 11, 37, 150, 42, 232}
- bytes1 := []byte{8, 145, 78, 18, 124, 101, 121, 74, 119, 97, 87, 81, 105, 79, 106, 73, 120, 77, 106, 89, 119, 77, 68, 77, 115, 73, 109, 57, 119, 90, 87, 53, 102, 97, 87, 81, 105, 79, 105, 73, 120, 77, 68, 65, 119, 77, 106, 73, 49, 73, 105, 119, 105, 100, 72, 81, 105, 79, 106, 69, 50, 78, 84, 81, 49, 79, 68, 77, 121, 77, 84, 81, 115, 73, 109, 104, 104, 99, 50, 103, 105, 79, 105, 74, 106, 89, 50, 82, 107, 90, 87, 73, 50, 89, 50, 81, 51, 78, 84, 69, 50, 77, 84, 85, 49, 89, 87, 77, 52, 90, 71, 69, 122, 78, 87, 85, 121, 77, 50, 82, 108, 77, 122, 107, 49, 90, 83, 74, 57}
- loginRequest := &pb.UserLoginRequest{}
- err := protobuf.Unmarshal(bytes, loginRequest)
- if err != nil {
- fmt.Println(err)
- }
- err = protobuf.Unmarshal(bytes1, loginRequest)
- if err != nil {
- fmt.Println(err)
- }
- }
- func TestPrintBytes(t *testing.T) {
- str := "[81 01 08 91 4E 12 7C 65 79 4A 77 61 57 51 69 4F 6A 49 78 4D 6A 59 77 4D 44 4D 73 49 6D 39 77 5A 57 35 66 61 57 51 69 4F 69 49 78 4D 44 41 77 4D 6A 49 31 49 69 77 69 64 48 51 69 4F 6A 45 32 4E 54 51 31 4F 44 4D 79 4D 54 51 73 49 6D 68 68 63 32 67 69 4F 69 4A 6A 59 32 52 6B 5A 57 49 32 59 32 51 33 4E 54 45 32 4D 54 55 31 59 57 4D 34 5A 47 45 7A 4E 57 55 79 4D 32 52 6C 4D 7A 6B 31 5A 53 4A 39]"
- printBytes(str)
- }
- func printBytes(str string) {
- str = strings.Replace(str, "[", "", -1)
- str = strings.Replace(str, "]", "", -1)
- strList := strings.Split(str, " ")
- output := "[]byte{"
- for i, s := range strList {
- output += s
- if i < len(strList)-1 {
- output += ","
- }
- }
- output += "}"
- fmt.Println(output)
- }
|