关于C# 用Google Protocol Buffers 压缩数据传输到服务器 服务器用C++ 调用Google Protocol Buffers 解包
我们现在遇到的问题是 C# 用Google的缓存协议打包 自己解是可以解出来的  但是到了服务器端 C++调用Google缓存协议
解包就出现问题 解出来的数据不对

解决方案 »

  1.   

    LZ  我在看啊、  对C++不是特别的了解、还是顺便看看别人怎么说、   帮LZ顶了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      

  2.   

    没有人 用过google的缓存协议吗
      

  3.   

    这是Protocol Buffers主页上的一段代码:message Person {
    required string name = 1;
    required int32 id = 2;
    optional string email = 3;enum PhoneType {
    MOBILE = 0;
    HOME = 1;
    WORK = 2;
    } message PhoneNumber {
    required string number = 1;
    optional PhoneType type = 2 [default = HOME];
    }repeated PhoneNumber phone = 4;
    } 而Protocol Buffers的作用,就是将以上格式的数据类型,自动生成Java, Python, and C++的代码,然后以下一系列代码就可以直接调用了:(C++中)Person person;
    person.set_name("John Doe");
    person.set_id(1234);
    person.set_email("[email protected]");
    fstream output("myfile", ios::out | ios::binary);
    person.SerializeToOstream(&output); fstream input("myfile", ios::in | ios::binary);
    Person person;
    person.ParseFromIstream(&input);
    cout << "Name: " << person.name() << endl;
    cout << "E-mail: " << person.email() << endl;
      

  4.   


            /// <summary>
            /// 打包预警参数为byte字节流数组
            /// </summary>
            /// <param name="list"></param>
            /// <returns></returns>
            public static byte[] SerializeConnditionMonitor(Collection<ConnditionMonitor> list)
            {
                byte[] readBuffer = new byte[BufferLength];
                using (MemoryStream ms = new MemoryStream())
                {
                    Serializer.Serialize<Collection<ConnditionMonitor>>(ms, list);
                    readBuffer = ms.ToArray();            }
                return readBuffer;
            }这个是我的C#客户端 采用google缓存协议 打包的数据  打包完后将这个byte[] 数组发到服务器的
    但是到了服务器 C++用google缓存协议在解的时候就出现错误 我现在怀疑的是 是不是google缓存协议不支持 一端用C#打包  一端用C++解包
    请高人指教。
      

  5.   

    .NET的字符串都是UTF-16编码,默认以UTF-8输出...解码时编码要匹配...
      

  6.   

    楼主还在吗? 我也遇到了这个问题。就是一段C++ 一端C# 中文解析不正确。我怀疑 C++的是UTF8的  C#是unicode的。 请问 你解决这个问题了嘛