protobuf-net

Serializing dynamic type parameter Protobuf-net

依然范特西╮ 提交于 2019-12-10 10:39:44
问题 Possible duplicates without answers: here and here. I am trying to serialize a class with a params object array using protobuf-net (2.0.0.668). There can be different types in my params object[]. When using DataContractSerializer, simply using [KnownType] works like expected. I understand that it isn't the case for protobuf-net, and that I must use [ProtoInclude] instead, along with DynamicType = true , like so: [ProtoContract, ProtoInclude(20, typeof(Int32))] //Int32 as an example public

Protobuf-net generic inheritance and closed constructed generic type

核能气质少年 提交于 2019-12-10 10:26:38
问题 I have a fairly complex inheritance hierarchy including generics and we are trying to use protobuf .net for serialization purposes. Unfortunately it does not seem to be able to handle this case correctly. This is how the hierarchy looks like. [System.Runtime.Serialization.DataContract] [ProtoBuf.ProtoInclude(1000, typeof(GenericBaseClass<object>))] [ProtoBuf.ProtoInclude(1001, typeof(GenericBaseClass<string>))] public abstract class BaseClass { public int BaseProperty1 { set; get; } public

How can I persist an array of a nullable value in Protobuf-Net?

感情迁移 提交于 2019-12-10 10:12:37
问题 I am in the process of migrating from BinaryFormatter to Protobuf-net (which so far appears to offer HUGE improvements both in terms of storage size and deserialization time). A problem I've encountered however is that double?[] arrays do not deserialize in the same form they were serialized. Any values in the array that are null get removed in their entirety - i.e. if I start with an array with 6 elements of [null, null, 1, 2, 3, null], after deserialization I end up with an array of [1, 2,

Protobuf-net RuntimeTypeModel not serializing members of base class

落爺英雄遲暮 提交于 2019-12-10 10:11:56
问题 Say I have the following base class: [DataContract] [Serializable] public abstract class DimensionEntity { [DataMember(Order = 1)] private readonly Date effectiveDatespan; ... } And the following derived class: [DataContract] [Serializable] public class ClearingSite : DimensionEntity { [DataMember(Order = 1)] private readonly string code; ... } When I serialize an instance of ClearingSite as follows: model.Add(typeof(ClearingSite), true); model.Serialize(ms, clearingSite); I can see that only

ProtoBuf-net AsReference require public constructor in Activator.CreateInstance?

百般思念 提交于 2019-12-10 06:01:09
问题 While working on 2 of my classes that looks like this (minimal) using System; using System.Collections.Generic; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using System.IO; using ProtoBuf; namespace Sandbox { public partial class Form1 : Form { public Form1() { Family family = new Family(); Child child1 = new Child(1); Child child2 = new Child(2); Parent parent = new Parent(new List<Child>() { child1, child2 }); family.Add(parent);

Serialize object[] with Protobuf-net

给你一囗甜甜゛ 提交于 2019-12-10 05:10:30
问题 I would like to serialize and deserialize some values stored in an object array. public class Sample { public object[] Data; } I know at run-time what types to expect in the array. In effect I want to treat Data inside of Sample as a message stream. Individually, I know I can use Serializer.NonGeneric.SerializeWithLengthPrefix to write each object out using a PrefixStyle.Base128 and make a Prefix->Type map for the Deserialise Type-Resolver. See What is protobuf-net SerializeWithLengthPrefix

For which scenarios is protobuf-net not appropriate?

烈酒焚心 提交于 2019-12-09 13:11:16
问题 We have been using BinarySerialization with our C# app, but the size and complexity of the classes which need to be serialized results in sloooooow (de)serialization, and large files. We suspect that we should just write our own custom serializers; but protobuf-net claims significant speed and size advantages over standard .Net binary serialization, and may be easier to add to our app than a large number of bespoke serializers. Before spending significant time and effort trying to get it to

How to serialize/deserialize large list of items with protobuf-net

此生再无相见时 提交于 2019-12-09 10:00:00
问题 I have a list of about 500 million items. I am able to serialize this into a file with protobuf-net file if I serialize individual items, not a list -- I cannot collect the items into List of Price and then serialize because I run out of memory. So, I have to serialize one record at a time: using (var input = File.OpenText("...")) using (var output = new FileStream("...", FileMode.Create, FileAccess.Write)) { string line = ""; while ((line = input.ReadLine()) != null) { Price price = new

How RuntimeTypeModel can be used to associate ProtoInclude with a type in protobuf-net?

我们两清 提交于 2019-12-09 07:03:53
问题 As I understood, RuntimeTypeModel allows to associate ProtoInclude with a type, which is useful for cases when the type declaration cannot be changed. But I find it hard to understand how it is actually done. Is there an example? Thanks. 回答1: AddSubType() is used to specify derived types, along with their identifier; for example (full code): static RuntimeTypeModel CreateModel() { var model = TypeModel.Create(); model[typeof(NotInvolved)].Add(1, "D"); model[typeof(SomeBase)] .Add(1, "A")

Any proper way of sending byte data to Unity3D from a C plugin?

六眼飞鱼酱① 提交于 2019-12-08 16:38:28
问题 Just a question of curiosity here. When you write plugins for Unity on the iOS platform, the plugins have a limited native-to-managed callback functionality (from the plugin and then to Unity). Basically this documentation: iOS plugin Unity documentation states that the function signature you are able to call back to is this: Only script methods that correspond to the following signature can be called from native code: function MethodName(message:string) The signature defined in C looks like