protobuf-net

Lazy, stream driven object serialization with protobuf-net

本秂侑毒 提交于 2020-01-01 11:36:04
问题 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

Protobuf.NET using

谁都会走 提交于 2020-01-01 06:54:31
问题 Need to send some data between managed c# and unmanaged c++. After some research I tried to use Protobuf.NET. I'm not sure if I understand functionality of ProtoBuf... Build a type definition in Proto. I need this type definition in both projects c++ and c# Use the command-line tool "protogen.exe" to get an .cs file and .cpp, .h from the type definition Copy the .cs files into my c# project and the .cpp, .h in my c++ solution. Seems I'm to stupid to to solve this. Here are my problem and

protobuf-net implicit contracts

…衆ロ難τιáo~ 提交于 2020-01-01 06:54:11
问题 Does anyone have a working example where protobuf-net can be used as a drop-in replacement for BinaryFormatter? Is that even possible? Actually I just need a serializer for one message type which looks like public class A { public B[] Bs { get;set; } public C[] Cs { get;set; } } All types are defined in a different assembly and have a lot of properties. Is there an option to automatically generate proto contracts with all public properties included, for class A and other used types (B, C), so

Protobuf-net object reference deserialization using Dictionary: A reference-tracked object changed reference during deserialization

对着背影说爱祢 提交于 2020-01-01 02:41:15
问题 I'm having some issues trying to serialize/deserialize a complex object graph using protobuf-net. I'm working on a legacy application and we're using .Net Remoting to connect a GUI client to a C# service. We are seeing poor performance with overseas users due to the serialized size of our object graphs using the default BinaryFormatter , which is exacerbated by the limited bandwidth in-between the client and server (1Mbit/s). As a quick win, I thought I'd put together a proof of concept to

protobuf.net & conditional serialization

别来无恙 提交于 2019-12-31 04:49:07
问题 We are using protobuf.net to serialize classes between mobile devices and back end services, but we now need to adjust what is sent back to the client based upon the 'context' of the user. We would typically do this by implementing the ISerializable interface and look at the context value to then decide what to serialize. Similarly in the constructor we would then deserialize the provided values. But it would appear that ISerializable isn't implemented/support (i can see why) for protobuf.net

Protobuf-net: Serializing a 3rd party class with a Stream data member

做~自己de王妃 提交于 2019-12-31 03:04:08
问题 How do you serialize a Stream (or more correctly Stream derived) data member of a class? Assuming we have a 3rd Party class that we can't attribute: public class Fubar { public Fubar() { ... } public string Label { get; set; } public int DataType { get; set; } public Stream Data { get; set; } // Where it's always actually MemoryStream }; I'm trying to use protobuf-net to serialize the class. Working through the exceptions and various SO questions I've come up with: RuntimeTypeModel.Default

Does protobuf-net support nullable types?

情到浓时终转凉″ 提交于 2019-12-30 16:52:10
问题 Is it possible to generate nullable members in protobuf-net? message ProtoBuf1 { optional Int32? databit = 1; optional Nullable<bool> databool = 2; } 回答1: Yes, but it doesn't generate them by default if you are doing codegen from .proto. If this is just C#, of course, you don't need a .proto - just: [ProtoContract] public class ProgoBuf1 { [ProtoMember(1)] public int? Foo {get;set;} [ProtoMember(2)] public float? Bar {get;set;} } If you are working from .proto, you could consider copying and

How to Serialize Inherited Class with ProtoBuf-Net

我只是一个虾纸丫 提交于 2019-12-29 03:37:07
问题 I am sorry if this is a duplicate. I have searched several places for an answer that I might understand including: ProtoBuf.net Base class properties is not included when serializing derived class Serialize inherited classes using protobuf-net My apologies but I did not really understand the answers. I am looking for a faster more compact binary serializer and ProtoBuf looks like it might be the answer. I need to serialize a set of classes that all derive from a single base class. There are a

What does the ProtoInclude attribute mean (in protobuf-net)

空扰寡人 提交于 2019-12-29 03:31:05
问题 In the ProtoBuf-Net implementation, what does the ProtoInclude attribute mean, and what does it do? An example would be appreciated. I saw it in this post and I'm not sure what it does. The example was: [Serializable, ProtoContract, ProtoInclude(50, typeof(BeginRequest))] abstract internal class BaseMessage { [ProtoMember(1)] abstract public UInt16 messageType { get; } } [Serializable, ProtoContract] internal class BeginRequest : BaseMessage { [ProtoMember(1)] public override UInt16

Exception serializing custom collection

孤者浪人 提交于 2019-12-24 17:55:56
问题 Thanks for the great library Marc and for all the answers on SO. I'm using protobuf-net r480.zip on .NET 4.0.zip from http://code.google.com/p/protobuf-net/downloads/list. Is this the latest stable release? I'm having trouble serializing a custom collection. public static void TestSerialization() { using (var stream = new MemoryStream()) { var b1 = new B1 { 1 }; // Throws System.ArgumentException: Repeated data (a list, collection, etc) has inbuilt behaviour and cannot be subclassed