tavenzhang / protoc-gen-as3

Automatically exported from code.google.com/p/protoc-gen-as3
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

AS3 生成数据与C++生成数据不一致 #32

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
协议内容如下:

message C10001{
    required string account = 1;
    required bytes password = 2;
}

用 as3crypto 的 sha256 对 password 
进行处理后进行字用protoc-gen-as3串化,打印出来发现跟C++生成
的二进制数据有一位不一样,目前分析Sha256后的数据两种语��
�是一直的,说以不知道问题是不是出现在串化过程中
两种语言串化的二进制数据如下(不包含括号,括号是我加��
�去突出不同的那个位置的)
AS3:6433130303031a561646d696e1220ba7816bf8f1cfea414140de5dae2223b0361a396177a9cb
410ff61f2
C++:6433130303031a561646d696e121dba7816bf8f1cfea414140de5dae2223b0361a396177a9cb
410ff61f2

AS的代码如下:
import com.hurlant.crypto.Crypto;
            import com.hurlant.crypto.hash.IHash;
            import com.hurlant.util.Hex;
            import com.netease.protobuf.*;

            import msg.*;

            private function CK():void{

                var hash:IHash = Crypto.getHash("sha256");
                var data1:ByteArray = Hex.toArray(Hex.fromString("abc"));

                var msgA:C10001 = new C10001();
                msgA.account = "admin";
                msgA.password = hash.hash(data1);

                var cN:String = getQualifiedClassName(msgA);
                cN=cN.substr(cN.lastIndexOf(':')+1);

                var data:ByteArray = new ByteArray();
                data.writeByte(cN.length);
                data.writeUTFBytes(cN);

                msgA.writeTo(data);

                var code:String = "";
                for(var i:int=0; i < data.length; i++){
                    code += data[i].toString(16);
                }

                trace(code);

            } 

Original issue reported on code.google.com by CChunq...@gmail.com on 23 May 2012 at 6:18

GoogleCodeExporter commented 9 years ago
AS3:6433130303031a561646d696e12(20)ba7816bf8f1cfea414140de5dae2223b0361a396177a9
cb410ff61f2
C++:6433130303031a561646d696e12(1d)ba7816bf8f1cfea414140de5dae2223b0361a396177a9
cb410ff61f2

Original comment by CChunq...@gmail.com on 23 May 2012 at 6:21

GoogleCodeExporter commented 9 years ago
1. protoc-gen-as3生成的数据正确无误。
2. 你贴出来的代码有误:
code += data[i].toString(16);
这行代码应改为
code += (data[i] % 8).toString(16);
code += uint(data[i]).toString(16);

Original comment by pop.atry@gmail.com on 23 May 2012 at 7:30

GoogleCodeExporter commented 9 years ago
那为什么protoc-gen-as3生成的数据的数据给C++ 
转不会来,就这个协议不行,其他协议都可以转化过去

Original comment by CChunq...@gmail.com on 23 May 2012 at 10:45

GoogleCodeExporter commented 9 years ago
你转十六进制字符串的代码写错了
你给C++用了不同的数据

Original comment by pop.atry@gmail.com on 23 May 2012 at 3:53