首页 > 解决方案 > 如何处理 cocos2d-js 中的 []byte 流?

问题描述

我的游戏是由 cocos2d-js 开发的。在这里我面临一个挑战,我们使用 tcp-socket 与后端通信。

套接字有它的流规则,即

[4]byte totalLength big endian
[4]byte headerLength big endian
[4]byte bodyLength big endian
[]header header stream, marshalled by json
[]body body stream, marshalled by json

好的,这里如何在 cocos-2d-js 中很好地对其进行编码/解码

function encode(header, body) {
    return buf
}

function decode(buf) {
    return header,body
}

标签: cocos2d-js

解决方案


推荐阅读