Git Product home page Git Product logo

Comments (11)

xxl6097 avatar xxl6097 commented on June 2, 2024

image

zinx:1.1.2版本,1.1.0 无任何问题

你的协议是什么样的?如果没有设置解码器,默认是TLV格式协议.最好附上你的测试数据

from zinx.

clukboy avatar clukboy commented on June 2, 2024

image
zinx:1.1.2版本,1.1.0 无任何问题

你的协议是什么样的?如果没有设置解码器,默认是TLV格式协议.最好附上你的测试数据

我使用的是默认的配置,任务东西都没有碰。下面是我的测试数据
image

from zinx.

xxl6097 avatar xxl6097 commented on June 2, 2024

我解释一下,这里存在两个问题:
1、client.GetPacket().Pack,这里的Pack使用的是小端模式,但是服务器默认是大端;
2、这里的Pack封装的是LTV模式,但是服务器默认是是TLV,请一定注意写msgID和dataLen的前后顺序

代码如下:


func Pack(msg ziface.IMessage) ([]byte, error) {
	dataBuff := bytes.NewBuffer([]byte{})
	//写msgID
	if err := binary.Write(dataBuff, binary.BigEndian, msg.GetMsgID()); err != nil {
		return nil, err
	}

	//写dataLen
	if err := binary.Write(dataBuff, binary.BigEndian, msg.GetDataLen()); err != nil {
		return nil, err
	}

	//写data数据
	if err := binary.Write(dataBuff, binary.BigEndian, msg.GetData()); err != nil {
		return nil, err
	}

	return dataBuff.Bytes(), nil
}

func main() {
	client := znet.NewClient("127.0.0.1", 8999)
	client.SetOnConnStart(func(conn ziface.IConnection) {
		//msg, _ := client.GetPacket().Pack(zpack.NewMsgPackage(0, []byte("hello")))
		msg, _ := Pack(zpack.NewMsgPackage(0, []byte("hello")))
		//请注意,msg数据在zpack中使用的小端模式,但是服务器默认是大端哦
		zlog.Ins().DebugF("send msg %s \n", hex.EncodeToString(msg))
		_, err := conn.GetConnection().Write(msg)
		fmt.Println(err)
	})

	client.Start()
	select {}
}

from zinx.

xxl6097 avatar xxl6097 commented on June 2, 2024

请阅读aceld/[email protected]/examples/LTVDecoder.go文件,专门针对LTV协议格式做出的解释与处理

from zinx.

clukboy avatar clukboy commented on June 2, 2024

PackData 下面的Pack 是否需要更新一下呢,他这里还是使用的先DataLen 在msgID的
image

from zinx.

clukboy avatar clukboy commented on June 2, 2024

我使用protobuf来传输数据的时候,他解析出来也是存在问题的。proto unmarshal err:proto: cannot parse invalid wire-format data,我通过断点查看,MsgData其实并没有把MsgId和DataLen去除,还是在包里面的,这样的话就等于还需要自己重新解析一次
image
这是我处理数据的地方
image

from zinx.

clukboy avatar clukboy commented on June 2, 2024

我看了,使用这个解码采用的response来读取数据没问题,但是如果不采用的话根本就无法读取到数据,只能读取到MsgId和DataLen

from zinx.

aceld avatar aceld commented on June 2, 2024

@clukboy 确实,,我们应该先兼容一下之前的,这个原因是近期我们新增了一套解码器,可以提供自定义报文格式的,可能在之前暴露出来的接口没有兼容好,你可以先用下v1.1.0, 这几天我们会兼容下之前的接口,之后会打个tag,在这里回复。

from zinx.

xxl6097 avatar xxl6097 commented on June 2, 2024

使用v1.1.3版本,解决以上问题

from zinx.

clukboy avatar clukboy commented on June 2, 2024

使用v1.1.3版本,解决以上问题

image

还是不行,数据还是没有解析,应该默认是不初始化解码器才是正确的,由用户来初始化解码器就行了

from zinx.

xxl6097 avatar xxl6097 commented on June 2, 2024

使用v1.1.3版本,解决以上问题

image

还是不行,数据还是没有解析,应该默认是不初始化解码器才是正确的,由用户来初始化解码器就行了

你这个地方说的没错,但是为了兼容以前版本,所以才设置默认。如果你不想要默认的,可以自行设置s.SetDecoder(nil)
使用v1.1.5版本目前存在的问题应该都已经解决!

from zinx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.