简体   繁体   English

在使用C#protobuf-net生成的Objective-c中反序列化“序列化Protobuf”的最佳方法是什么?

[英]What is the best way to Deserialize “Serialized Protobuf” in objective-c which is generated using C# protobuf-net

I have a Class that contains objects, arrays, int, and string too. 我有一个包含对象,数组,整数和字符串的类。

public class Template
    {
        [ProtoMember(1)]
        public string name;
        [ProtoMember(2)]
        public tempClass contour;
        [ProtoMember(3)]
        .
        .
        .
  }

//And here is the Serializing code (Using protobuf-net)
 using (var file = File.Create("Templates.bin"))
            {
                Serializer.Serialize<Template[]>(file, tempArray);
            }

I know it can be deserializeable using Objective-c. 我知道可以使用Objective-c将其反序列化。 i tried some solution but did not succeeded yet. 我尝试了一些解决方案,但尚未成功。

have anyone done this before? 有人做过吗? is that better to use XML instead of Protobuf? 使用XML代替Protobuf更好吗?

That will map to (in .proto terms): 这将映射到(以.proto术语):

message templateWrapper {
    repeated template items = 1;
}
message template {
    optional string name = 1;
    optional tempClass contour = 2;
    // ...
}
message tempClass {
    // ...
}

And then deserialize as a single templateWrapper , which will have multiple items . 然后反序列化为单个templateWrapper ,它将具有多个items

Note that all of the .proto schema except for the templateWrapper should be available via Serializer.GetProto<Template>() . 请注意,除templateWrapper之外的所有.proto模式都应该可以通过Serializer.GetProto<Template>()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM