最近在進行egret開發時,前後端的協議使用了protobuf,在解析數據的時候出現了一些問題,我在這裏大致把我的解決方案貼出來,以備自己以後查閱。
//buffer爲我們得到的egret.ByteArray
//values爲this.length - this.postion
var bytes: Unit8Array = new Unit8Array(values);
buffer.readBytes(new ByteArray(bytes.buffer), 0, value.bytelength);
//protobuf對象爲protoObject
protoObject.decode(bytes);
因爲涉及到公司的代碼,所以只能大致用這種類似僞代碼的形式描述一下,希望可以有所幫助。