protobuf-net

Protobuf-net serialization error = “The type cannot be changed once a serializer has been generated”

穿精又带淫゛_ 提交于 2020-01-14 12:58:11
问题 The following scenario seems to cause the exception in Protobuf.net on deserialization. Have I done something wrong? Is there a way round this? [ProtoContract] [ProtoInclude(2, typeof(Ant))] [ProtoInclude(3, typeof(Cat))] public interface IBeast { [ProtoMember(1)] string Name { get; set; } } [ProtoContract] public class Ant : IBeast { public string Name { get; set; } } [ProtoContract] public class Cat : IBeast { public string Name { get; set; } } [ProtoContract] [ProtoInclude(1, typeof

protobuf-csharp-port - streaming records from a file a bit like an axis function in LINQ-to-XML

浪子不回头ぞ 提交于 2020-01-14 04:28:09
问题 I have built the standard address book tutorial that comes with protobuf-csharp-port and my code is as follows: class Program { static void Main(string[] args) { CreateData(); ShowData(); } private static void CreateData() { AddressBook.Builder abb = new AddressBook.Builder(); for (int i = 0; i < 2000000; i++) { Person.Builder pb = new Person.Builder(); pb.Id = i; pb.Email = "mytest@thisisatest.com"; pb.Name = "John" + i; abb.AddPerson(pb.Build()); } var ab = abb.Build(); var fs = File.Create

ProtoBuf-Net error message “ Invalid field in source data: 0”

我是研究僧i 提交于 2020-01-13 05:45:41
问题 I succeed in serializing instances of the following class but when I try to deserialize right after I get the following error message: " Invalid field in source data: 0" . I have no clue what it refers to because I find below class straight forward. I just updated protobuf-net version to 2.00.614 (runtime version: 2.0.50727). Any idea whether I am possibly overlooking something trivial? [ProtoContract] public class TimeSeriesProperties { [ProtoMember(1)] public string TimeSeriesName { get;

Does protobuf-net support [DataMember(Order=0)]?

大憨熊 提交于 2020-01-11 09:43:30
问题 I am using protobuf-net with WCF, and finding that data members with Order = 0 are not showing up on the client. Here is my data contract - ObjectId is always Guid.Empty on the client side. <DataContract()> _ Public Class ProtocolBufferDataContract <DataMember(Order:=0)> _ Public Property ObjectId() As Guid <DataMember(Order:=1)> _ Public Property Title() As String End Class I am using the shared-assembly mechanism, so both the server and client are compiled against this class. If I change

Using ProtoBuf-Net, how to (de)serialize a multi-dimensional array?

此生再无相见时 提交于 2020-01-10 02:53:17
问题 Since ProtoBuf-Net does not support serializing/deserializing multi-dimensional arrays, how would I go about managing my arrays? 回答1: This is essentially a limitation of the underlying protobuf wire format; it only supports single-dimension arrays. Two options leap to mind; firstly, send it as a linear array, and send the dimensions separately. You could also represent it as a list of objects that each has an array - essentially a jagged array, but with an intermediate step. Of the two, the

PROTOBUFF INT64 check aganist previously entered data c++

纵然是瞬间 提交于 2020-01-07 06:57:36
问题 message HealthOccurrenceCount { required int64 HealthID=1; required int32 OccCount=2; optional bytes wci=3; } I would like to add data based on HealthID ; If HealthID is already entered then instead of adding a new entry, the program should instead just increment the existing entry's OccCount . HealthOccurrenceCount objHelthOccCount; if(objHelthOccCount.healthid() == healthID) // Is this right or do I need to iterate all the nodes? { occCount++; objHelthOccCount.set_occcount(occCount); } else

Why does the following trivial C# code raise a ProtoException about a missing default constructor?

▼魔方 西西 提交于 2020-01-06 04:40:27
问题 Here is the code: using System.Diagnostics; using System.IO; using ProtoBuf; namespace ProtoBufTest { [ProtoContract] [ProtoInclude(13, typeof(BuildEvent))] public abstract class Event { [ProtoMember(1)] public int NodeId { get; set; } } [ProtoContract] public class BuildEvent : Event { } public class Program { static void Main(string[] args) { var ms = new MemoryStream(); Serializer.SerializeWithLengthPrefix<object>(ms, new BuildEvent(), PrefixStyle.Base128); Debug.WriteLine(ms.Position); ms

Protobuf-net memcache provider fails on append/set ArraySegment

北战南征 提交于 2020-01-05 10:32:08
问题 I'm using protobuf-net lib with protobuf-net memcache provider and I'm trying to use memcache append function: var data = new ArraySegment<byte>(Encoding.UTF8.GetBytes("appendedString")); var result = _memcache.ExecuteStore(StoreMode.Add, key, data); And it throws exception: The runtime has encountered a fatal error. The address of the error was at 0x63765a43, on thread 0xd58. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user

protobuf-net faulty enum exception (issue 422) need a good workaround

天大地大妈咪最大 提交于 2020-01-05 10:32:05
问题 I am working in a project that uses ProtoBuf in different languages among them .NET. For .NET we use protobuf-net. We have extended enums and they work on the other platforms but in .NET we get a exception when trying to de-serialize. When googling this i found this Issue 422. Does anyone have a good workaround or know what to download and compile for a local fix. We would prefer not to introduce weird extra enums or other weird stuff that goes against the Protobuf definition. 来源: https:/

protobuf-net deserialize base class to inherited class

≯℡__Kan透↙ 提交于 2020-01-05 07:21:20
问题 I have base class which is serialized. [ProtoContract] public class Web2PdfEntity { [ProtoMember(1)] public string Title { get; set; } [ProtoMember(2)] public string CUrl { get; set; } } I would like to deserialize Web2PdfEntity class to Web2PdfServer which is inherited from Web2PdfEntity. public class Web2PdfServer : Web2PdfEntity { public void MyServerMethod {} public void MyServerMethod2{} } I have tried to use code below to deserialize class, unfortunately the properties are not set. var