protobuf-net

ProtoBuf-net Deserialize does not work

心不动则不痛 提交于 2019-12-12 03:48:19
问题 code is here: var responseMsg = new ResponseMessage() { code = ErrorCode.OK, type = MsgType.LOGIN, responseStr = "this is local server" }; var serverStream = new MemoryStream(); ProtoBuf.Serializer.Serialize(serverStream, responseMsg); Console.WriteLine($"responseMsg {responseMsg?.responseStr ?? "failed"}\n"); var response =ProtoBuf.Serializer.Deserialize<ResponseMessage>(serverStream); Console.WriteLine($"response {response?.responseStr ?? "failed"}\n"); result is responseMsg this is local

protobuf-net : IExtensible not supported for inheritance

一世执手 提交于 2019-12-12 03:43:47
问题 It does not seem possible to implement protobuf-net serialization for classes that define their sub-types via [ProtoInclude] and implement ProtoBuf.IExtensible : [ProtoBuf.ProtoInclude(1000, typeof(DerivedClass))] public partial class BaseClass : ProtoBuf.IExtensible { ... private IExtension extensionObject; IExtension IExtensible.GetExtensionObject(bool createIfMissing) { return Extensible.GetExtensionObject(ref extensionObject, createIfMissing); } } public partial class DerivedClass :

C# send/receive Collections using protobuf-net + sockets example

家住魔仙堡 提交于 2019-12-11 20:37:52
问题 I'm looking for complete example of how to transfer collections between 2 machines by using protobuf-net serialization and sockets connection. All I succeed to find is separate parts of code and no one of them can't explain to the noob like me how to combine all this stuff. Following the .proto file: using System; using ProtoBuf; namespace Proto.Transaction { [Serializable] [ProtoContract] public class Transaction { [ProtoMember(1)] public int Type { get; set; } [ProtoMember(2)] public int

Custom protobuf-net RuntimeTypeModel in Unity3D - Could not load file or assembly

此生再无相见时 提交于 2019-12-11 19:07:29
问题 I am trying to build a custom protobuf-net RuntimeTypeModel in Unity3D with this function: private static RuntimeTypeModel GetModel() { RuntimeTypeModel typeModel = TypeModel.Create(); foreach (var t in GetTypes(CompilationPipeline.GetAssemblies())) { var contract = t.GetCustomAttributes(typeof(ProtoContractAttribute), false); if (contract.Length > 0) { typeModel.Add(t, true); //add unity types typeModel.Add(typeof(Vector2), false).Add("x", "y"); typeModel.Add(typeof(Vector3), false).Add("x",

Help needed with the most trivial protobuf-net example

被刻印的时光 ゝ 提交于 2019-12-11 13:05:12
问题 Observe the following trivial piece of code: [ProtoContract] public class B { [ProtoMember(1)] public int Y; } [ProtoContract] public class C { [ProtoMember(1)] public int Y; } class Program { static void Main() { var b = new B { Y = 2 }; var c = new C { Y = 4 }; using (var ms = new MemoryStream()) { Serializer.Serialize(ms, b); Serializer.Serialize(ms, c); ms.Position = 0; var b2 = Serializer.Deserialize<B>(ms); Debug.Assert(b.Y == b2.Y); var c2 = Serializer.Deserialize<C>(ms); Debug.Assert

ProtoBuf-Net: Inheriting [ProtoMember] of type object[] from a parent class

二次信任 提交于 2019-12-11 12:59:23
问题 The object[] mList holds whatever objects that the child collection wants it to. This is supposed to be a dummy wrapper class for the rest of the more specified collections of objects. [ProtoInclude(98, typeof(Object1CollectionProto))] [ProtoInclude(99, typeof(Object2CollectionProto))] [ProtoInclude(100, typeof(Object3CollectionProto))] public class ObjectCollectionProto { protected ObjectType mCollectionType; protected object[] mList; public ObjectCollectionProto(){} [ProtoMember(1),

Protobuf .NET serialization for inheritance classes

时光总嘲笑我的痴心妄想 提交于 2019-12-11 12:24:03
问题 I'm trying to migrate my code serializer from NetDataContract to Protobuf.Net. Let's consider the following class example to help the understanding: [DataContract(Name "a", IsReference = true)] class Test { [DataMember(Name = "a")] public int Id { get; set; } [DataMember(Name = "b")] public string Name { get; set; } } To be able to use Protobuf .NET using DataContract, I'm using the following options: RuntimeTypeModel.Default.InferTagFromNameDefault = true; RuntimeTypeModel.Default

protobuf.net Handling of Nullable<DateTimeOffset>

寵の児 提交于 2019-12-11 11:55:05
问题 How can i serialize Nullable types with protobuf.net? This post tries to explain a few approaches: Can I serialize arbitrary types with protobuf-net? The problem is that there seems to be a bug with the surrogate approach in relation to Nullable, which is also mentioned in the linked post. The shim property approach is not suitable for us, mainly because we have many properties of this type. We are very keen on relying on protobuf.net for serialization as it matches our need for compact and

Replace binaryformatter by protobuf

拟墨画扇 提交于 2019-12-11 11:46:55
问题 I need to replace a library that store data in files (serialize/deserialize) This library do it currently using BinaryFormatter, but it's slow for large lists. Many posts here on stackoverflow show that protobuf is really performant, so I'm trying to use it. In order to make a replacement without rewriting a lot of code, my requirements are: Must serialize generic data, as I've to interface with Store<T>(T data) (most of time T is marked with DataContract and/or Serializable attribute) I can

What do I need to do to send out Protobuf serialized Data using C# ASP .NET web api?

不羁的心 提交于 2019-12-11 11:22:54
问题 I'm new to protobuf and fairly new to asp .net. so I might need help on this. I have this code snippet for my PersonsController: public class PersonController : ApiController { [ProtoContract] public class Person { [ProtoMember(1)] public int ID { get; set; } [ProtoMember(2)] public string First { get; set; } [ProtoMember(3)] public string Last { get; set; } } // GET api/values public IEnumerable<Person> Get() { List<Person> myList = new List<Person> { new Person { ID = 0, First = "Judy",