protobuf-net

protobuf-net - list supported types

拥有回忆 提交于 2019-12-10 18:23:09
问题 I'm working on a custom ProtoBufFormatter (: MediaTypeFormatter) that is capable of registering own types on the fly to the RuntimeTypeModel used to serialize/deserialze. To reduce the need of try{}catch{} blocks it would be great to filter out already supported types before adding them to the RuntimeTypeModel. The readme only offers a "vague" list types that are supported by default and the method Model.GetTypes() only returns a list of types that are manually added to the current model.

Protobuf-net serialization on sockets. No parameterless constructor found ProtoException

核能气质少年 提交于 2019-12-10 18:17:48
问题 I have created an application where interprocess communication is done using sockets. The procedure starts when a client connects with the server that I created and sends a serialized message. This message, I serialize using Protobuf-net, using SerializeWithLengthPrefix and deserialize it using DeserializeWithLengthPrefix. The client sends messages to the server who deserializes it perfectly, but the same is not true in the case of server to client. The main class is BaseMessage, which is

C# Protobuf-net: Dictionary of decimals: Zeroes don't get roundtrip properly

*爱你&永不变心* 提交于 2019-12-10 17:38:29
问题 I've found a weird bug around serialization/deserialization of decimal zeroes in protobuf-net, wondering if anyone has found a good workaround for this, or if this is actually a feature. Given a dictionary like above, if i run in linqpad: void Main() { { Dictionary<string, decimal> dict = new Dictionary<string, decimal>(); dict.Add("one", 0.0000000m); DumpStreamed(dict); } { Dictionary<string, decimal> dict = new Dictionary<string, decimal>(); dict.Add("one", 0m); DumpStreamed(dict); } }

ProtoBuf.net Base class properties is not included when serializing derived class

跟風遠走 提交于 2019-12-10 17:26:02
问题 Using latest 2.0 beta version of ProtoBuf.net I am trying to serialize derived class(just example) and I get empty file. Why base class properties is not serialized? [ProtoContract] [Serializable] public class Web2PdfClient : Web2PdfEntity { } [ProtoContract] [Serializable] public class Web2PdfEntity : EngineEntity { [ProtoMember(1)] public string Title { get; set; } [ProtoMember(2)] public string CUrl { get; set; } [ProtoMember(3)] public string FileName { get; set; } } [ProtoContract]

Is there a way to use IReadOnlyCollection<T>/IReadOnlyList<T> with protobuf-net

别说谁变了你拦得住时间么 提交于 2019-12-10 16:30:39
问题 I gather that when working with collections protobuf-net needs GetEnumerator for serialization and a type with Add for the deserialization. For types that don't have an Add you can set an inheriting type that does before deserialization. This works for example with IEnumerable and a List : [ProtoContract(ImplicitFields = ImplicitFields.AllPublic)] public class Sheep { public IEnumerable<string> Children { get; set; } public Sheep() { Children = new List<string>(); } } var dolly =

Can I serialize an object (containing members: Dictionary, List… etc) in Mono and deserialize it in MS.NET or vice versa by using protobuf-net?

有些话、适合烂在心里 提交于 2019-12-10 16:27:44
问题 I have a server running on MS.NET and a client on Mono (this is a Unity3D engine) and when i try to BinaryFormatter().Deserialize an object like this: [Serializable] public class Simulator { public IDictionary<int, Task> tasks = new Dictionary<int, Task>(); the client side cannot found/load types: Dictionary, List... The same "client code" running under MS.NET works good i.e. does not have any exceptions during deserialization. As i read from http://www.mono-project.com/FAQ:_Technical

How to serialize arrays?

故事扮演 提交于 2019-12-10 13:56:52
问题 Symptom: No serializer defined for type: System.Array Since all C# arrays inherit from the Array class, I thought that this would be valid in ProtoBuf-net [ProtoMember(1)] public Array SomeKindOfArray = new int[]{1,2,3,4,5}; [ProtoMember(2)] public List<Array> SomeKindOfList = new List<Array>(); Should I register Array with the RuntimeTypeModel? m.Add(typeof (Array), true); // does not seem to help Attempts: new int[]{1,2,3,4} // works (object)new int[] { 1, 2, 3, 4 } // does not work (Array

protobuf.net Unexpected subtype

[亡魂溺海] 提交于 2019-12-10 12:49:24
问题 I'm encountering this Exception in my project using Protobuf.net: InvalidOperationException "Unexpected sub-type: foo" I have a class which I'm sending which looks like this: class message { list<bar> listOfBars; } foo inherits off bar, However protobuf seems to choke on this and generate the exception above. Is there some way around this? I need to be able to hold all different subtypes of bar in the list, so a more type constrained solution would be difficult/impossible. 回答1: I may be

Protobuf C# Message Translation to JAVA

你。 提交于 2019-12-10 10:53:31
问题 I am trying to translate a message generated using C# to JAVA. As a first step, i generated proto file and this is what i got package Om.Business.Scanner; message ScannerActivityDetail { optional string ActivityId = 1; optional string ContextId = 2; optional int32 ActivityStart = 3; optional bcl.DateTime ActivityEnd = 4; } How do i interpret bcl.DateTime in java world? I am using protobuf-net and trying to de-serialize message generated by C# app. Thanks in advance for your help. 回答1: Looking

Is it possible to create a protobuf-net serialization assembly for Silverlight and .NET?

不想你离开。 提交于 2019-12-10 10:41:53
问题 I wonder if there is a tool like sgen for protobuf-net... 回答1: I haven't finished the tooling in that area, but note that RuntimeTypeModel has a Compile() method that takes a path and type name; this is the method you want. I suggest trying this from a "full" .NET console application to generate the ell then reference that from SL (also referencing the SL build of the protobuf-net dll). You might get an IDE warning about the reference, but from memory it should work. Long term I suspect I