“如何反序列化”;序列化的Protobuffer“;在c++;这是使用C#protobuf网络生成的

“如何反序列化”;序列化的Protobuffer“;在c++;这是使用C#protobuf网络生成的,c#,c++,protocol-buffers,protobuf-net,C#,C++,Protocol Buffers,Protobuf Net,我有一个结构 [ProtoContract] public struct TenprintTemplateStructure { [ProtoMember(1)] public byte[] FeatureTenprint { get; set; } //Tenpritn NTemplate's NBuffer [ProtoMember(2)] public int TemplateID { get; set; }

我有一个结构

[ProtoContract]
    public struct TenprintTemplateStructure
    {
        [ProtoMember(1)]
        public byte[] FeatureTenprint { get; set; } //Tenpritn NTemplate's NBuffer

        [ProtoMember(2)]
        public int TemplateID { get; set; } //Template ID

        [ProtoMember(3)]
        public long TemplateSize { get; set; } //Template Size

        [ProtoMember(4)]
        public string PersonID { get; set; } //Person ID

        [ProtoMember(5)]
        public int IsActive { get; set; } // Person's Status
    };
我正在使用长度前缀为Fixed32的c#proto buf将这个结构的多个实例序列化为一个文件。代码如下,(tenprintTemplateStruct是正在编写的结构)

我知道它可以用C++来抛弃。我尝试了一些解决办法,但还没有成功


以前有人这样做过吗?< /P> < P>在C++侧,你有4个步骤来执行:

    使用<代码> PotoCo/<代码>工具生成C++代码;您可以手动编写.proto模式,也可以使用
    stringproto=Serializer.GetProto()(来自.NET代码)作为起点
    
  • 从输入中读取4个字节,并将其解析为32位整数
    Fixed32
    被记录为小尾端,所以:这样做吧
  • 使用此长度的长度限制流包装实际流;谷歌对此做出了规定
  • 遵循实际反序列化的步骤-主要是

顺便说一句;附带问题:为什么这是一个
struct
?我身上的每一根骨头和肌肉都在尖叫,当我看着它的时候……这是我的代码:uint32 ByteSize=0;while(coded_input->ReadVarint32(&ByteSize)){CodedInputStream::Limit codedLimit=coded_input->PushLimit(ByteSize);TemplateData.ParseFromCodedStream(coded_input);coded_input->PopLimit(codedLimit);指纹节点*pFingerPrintNode=新指纹节点;this->->translateFromProtoBufftofFingerPrintNode(&TemplateData,pFingerPrintNode);此->AddToCache(pFingerPrintNode);}我应该使用ReadVarint32(&ByteSize)还是ReadLittleEndian32(&ByteSize)在while循环中??有什么区别吗C++中的“ReDeAdRealEnter 32()”。我是否应该使用C中的“TimBuff.PrimeStult.FixEd3BigeNeNeN”来写长度前缀?或者存在任何方法?@ ReZoAN如果你想用<代码> ReDaveRITIN 32 < /C>阅读,然后用<代码>前缀样式> Base128< /代码>编写。同样的事情,基本上。也许我的名字不太好。
ProtoBuf.Serializer.SerializeWithLengthPrefix(stream, tenprintTemplateStruct, ProtoBuf.PrefixStyle.Fixed32, 0);