| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package pb
- import (
- "f1-game/internal/pb"
- "strings"
- "testing"
- cherryString "github.com/cherry-game/cherry/extend/string"
- clog "github.com/cherry-game/cherry/logger"
- "google.golang.org/protobuf/proto"
- )
- func TestPB1(t *testing.T) {
- text := "[8 177 141 6]"
- v := pb.I32{}
- err := unmarshal(text, &v)
- clog.Debugf("v = %s", v.String())
- clog.Debugf("err = %v", err)
- }
- func unmarshal(text string, v proto.Message) error {
- bytes := text2Bytes(text)
- return proto.Unmarshal(bytes, v)
- }
- func text2Bytes(text string) []byte {
- text = strings.TrimSpace(text)
- text = strings.Replace(text, "[", "", -1)
- text = strings.Replace(text, "]", "", -1)
- textStrings := strings.Split(text, " ")
- var bytes []byte
- for _, t := range textStrings {
- value, _ := cherryString.ToUint(t, 0)
- bytes = append(bytes, uint8(value))
- }
- return bytes
- }
|