protobuf-net

Protobuf-Net as copy constructor

给你一囗甜甜゛ 提交于 2020-01-05 05:54:28
问题 is it possible to create a generic copy constructor based on protobuf-net? Something like: public class Person { public Int32 Id { get; set; } public String FirstName { get; set; } public Int32 Age { get; set; } public String Name { get; set; } } public static void DeepCopyCosntructor<T>(T source, T target) { // copy all properties by protobuf-net } I want to avoid reflection, but I don't know how to fill the properties of target without recreating a new object. 回答1: The issue to consider

protobuf-net : how to annotate properties of derived type?

一笑奈何 提交于 2020-01-04 05:44:13
问题 For the latest version of protobuf-net ( r640 folder ), how to best annotate a ProtoMember that is a derived type ? [ProtoBuf.ProtoContract(Name=@"MyBaseTypeProto")] [Serializable] public partial class MyBaseType: ProtoBuf.IExtensible { ... } [ProtoBuf.ProtoContract(Name=@"MyDerivedTypeProto")] [Serializable] public partial class MyDerivedType : MyBaseType, ProtoBuf.IExtensible { ... } [ProtoBuf.ProtoContract(Name=@"MyMessageProto")] [Serializable] public partial class MyMessage : ProtoBuf

Protobuf net not serializing when using WCF

点点圈 提交于 2020-01-04 05:08:30
问题 I am trying to use protobuf to serialize my WCF calls, but it seems the object is not getting serialized by the client. Some things to note: I am using a shared DTO library. I am using a ChannelFactory to invoke the service (so the types are not losing their datamember attributes). I can serialize and deserialize the objects just using normal protobuf.net code, so the types themselves seem to be ok I am using version 2.0.0.480 of protobuf.net I haven't posted the service code as the problem

have to create java pojo for the existing proto includes Map

妖精的绣舞 提交于 2020-01-02 10:04:36
问题 I have tried converting proto to java pojo . But got the error [Stderr] Order.proto:12:18: Expected "required", "optional", or "repeated". [Stderr] Order.proto:12:21: Expected field name. optional int32 orderID = 1; optional int32 quantity = 2; map<string,string> map_field = 4; repeated string product = 3; Please help me what needs to be changed. i searched on google protobuf developer site https://developers.google.com/protocol-buffers/docs/proto#maps It says that Map fields cannot be

Protobuf-net lazy streaming deserialization of fields

瘦欲@ 提交于 2020-01-02 08:13:13
问题 Overall aim : To skip a very long field when deserializing, and when the field is accessed to read elements from it directly from the stream without loading the whole field. Example classes The object being serialized/deserialized is FatPropertyClass . [ProtoContract] public class FatPropertyClass { [ProtoMember(1)] private int smallProperty; [ProtoMember(2)] private FatArray2<int> fatProperty; [ProtoMember(3)] private int[] array; public FatPropertyClass() { } public FatPropertyClass(int sp,

Protobuf-net root serialization integrity

↘锁芯ラ 提交于 2020-01-02 07:01:14
问题 I have two objects which reference each other. [JsonObject(IsReference = true)] [DataContract(IsReference = true, Namespace = "http://schemas.datacontract.org/2004/07/TrackableEntities.Models")] [ProtoContract] public class ProtoBufObject : ITrackable { [DataMember(Order = 3)] public Guid Oid { get; set; } [DataMember(Order = 4)] [ProtoMember(4, AsReference = true)] public ChildProtoBufObject child { get; set; } [DataMember(Order = 1)] public TrackingState TrackingState { get; set; }

Asynchronous protobuf serialization

六月ゝ 毕业季﹏ 提交于 2020-01-02 02:23:08
问题 A limitation of the protobuf-net implementation is that it calls the underlying streams synchronously. By not offering an asynchronous API e.g. BeginSerialize/EndSerialize or a TPL equivalent, we are forced to tie up a thread waiting for synchronous stream I/O. Is there any plan to offer asynchronous methods in protobuf-net, or alternatively, any creative ways around this problem? 回答1: No, that isn't currently supported and would be a lot of work. My suggestion would be: buffer data yourself

Serialize protocol buffer file into xml/text format

折月煮酒 提交于 2020-01-01 17:08:30
问题 I am using protocol buffer in .net http://code.google.com/p/protobuf-net/. I installed the visual studio support version, which I can just write proto file in project and it generates csharp class files automatically. A lot of times that I need to dump the files into xml(or another text format if available) file. I found that there is a method Serializer.Serialize() which takes an XmlWriter parameter. I tried to use it but it complains that the protobuf type I defined must be convertible to

Protobuf.net object graph serialization for lists

淺唱寂寞╮ 提交于 2020-01-01 12:06:27
问题 I understand that AsReference is not supported for lists with protobuf.net, so I have attempted a work-around for this limitation. I have created a custom list called SuperList that contains items wrapped in objects of type SuperListItem as follows: [ProtoContract] public class SuperList<T> where T : class { [ProtoMember(1)] private List<SuperListItem<T>> _items = new List<SuperListItem<T>>(); public SuperList() { } public int IndexOf(T item) { int indexOf = -1; for (int index = 0; index <

Lazy, stream driven object serialization with protobuf-net

折月煮酒 提交于 2020-01-01 11:36:45
问题 We are developing a WCF service for streaming a large amount of data, therefore we have chosen to use WCF Streaming functionality combined with a protobuf-net serialization. Context: Generally an idea is to serialize objects in the service, write them into a stream and send. On the other end the caller will receive a Stream object and it can read all data. So currently the service method code looks somewhat like this: public Result TestMethod(Parameter parameter) { // Create response var