protobuf-net

Protobuf-net possible recursion detected: serialize children and parents

柔情痞子 提交于 2019-12-23 11:58:06
问题 I am new to serialization in general, and even newer to protobuf. Here is my problem, I have these classes: [ProtoContract] class Controle { [ProtoMember(1, AsReference=true)] public HashSet<Controle> ControlesInternes { get; set; } [ProtoMember(2)] public string TypeControle { get; set; } [ProtoMember(3)] public Dictionary<string, string> Attributs { get; set; } [ProtoMember(4)] public int Ligne { get; set; } [ProtoMember(5)] public string InnerText { get; set; } [ProtoMember(6)] public

Why is ProtoBuf so slow on the 1st call but very fast inside loops?

▼魔方 西西 提交于 2019-12-23 11:53:07
问题 Inspired from this question. I created a small benchmark program to compare ProtoBuf, BinaryFormatter and Json.NET. The benchmark itself is a small console based one at https://github.com/sidshetye/SerializersCompare .Feel free to add/improve, it's quite simple to add a new serializer to the mix. Anyway, my results are: Binary Formatter ProtoBuf Json.NET ServiceStackJson ServiceStackJSV Loop Size:512 bytes Size:99 bytes Size:205 bytes Size:205 bytes Size:181 bytes 1 16.1242 ms 151.6354 ms 277

Why is ProtoBuf so slow on the 1st call but very fast inside loops?

你离开我真会死。 提交于 2019-12-23 11:52:27
问题 Inspired from this question. I created a small benchmark program to compare ProtoBuf, BinaryFormatter and Json.NET. The benchmark itself is a small console based one at https://github.com/sidshetye/SerializersCompare .Feel free to add/improve, it's quite simple to add a new serializer to the mix. Anyway, my results are: Binary Formatter ProtoBuf Json.NET ServiceStackJson ServiceStackJSV Loop Size:512 bytes Size:99 bytes Size:205 bytes Size:205 bytes Size:181 bytes 1 16.1242 ms 151.6354 ms 277

Decoding protobuf without schema

我怕爱的太早我们不能终老 提交于 2019-12-23 09:16:19
问题 Is it possible to decode protobuf serialized files without schema with tools or anything that would decode the binary data to readable format? 回答1: You can often deduce the schema. In fact, IIRC the "protoc" tool has a set of parameters ( --decode_raw , iirc) where it will do precisely that - making informed guesses. However, it is a guess - the format is ambiguous in that multiple different types of data can be stored in the same mechanisms - for example, a length-prefixed chunk could be: a

Can I re-use object instances to avoid allocations with protobuf-net?

柔情痞子 提交于 2019-12-23 08:58:17
问题 Context: this is based on a question that was asked and then deleted before I could answer it - but I think it is a good question, so I've tidied it, rephrased it, and re-posted it. In a high-throughput scenario using protobuf-net, where lots of allocations are a problem (in particular for GC), is it possible to re-use objects? For example by adding a Clear() method? [ProtoContract] public class MyDTO { [ProtoMember(1)] public int Foo { get; set; } [ProtoMember(2)] public string Bar { get;

Protobuf.net Exception - Timeout while inspecting metadata

为君一笑 提交于 2019-12-23 07:55:40
问题 I am sometimes receiving the following exception when attempting to deserialise an object using protobuf.net. I'm surprised as I never have more than a single thread deserialising the same object at the same time and the protobuf.net source does not seem to use any static objects for deserialising. The exception does suggest a solution but I am unsure as to how to implement so would welcome an example. Base Exception Type: System.TimeoutException: Timeout while inspecting metadata; this may

Is it possible to use Protobuf-Net with a class without a parameterless constructor?

巧了我就是萌 提交于 2019-12-23 07:48:43
问题 Using Protobuf-Net, I see that it does not seem possible to deserialize a class without having a parameterless constructor or I may be missing something? I don't want some of the classes with a parameterless constructor. Is there some kind of attributes that I could use or some other technique? 回答1: protobuf-net depends currently on having a parameterless constructor to work. However that constructor need not be public (it will use reflection if need be to invoke it) so you may be able to

Protocol Buffers with Extensions

爷,独闯天下 提交于 2019-12-22 10:00:04
问题 I'm perhaps overlooking something, but I'm attempting to wrestle protocol buffers into an easy method for providing extensions later. That seems a bit unclear so I'll jump directly into the problem. I am writing an assembly to support various tasks, one of which includes describing structured data. Perfect time to use protocol buffers. The primary class to use protocol buffers is called StateDefinition. Here's the .proto file I came up with for it: package Kannon.State; message

protobuf-net do not serialize List<T>

人走茶凉 提交于 2019-12-21 23:19:01
问题 I am trying to serialize List<T> but get empty file and List<T> won't serialize. I do not get any exception and read protobuf-net manual, all members which I want to serialize are marked with [ProtoContract] and [ProtoMember] atributes public void Save() { using (var outputStream = File.Create(SettingsModel.QueueListDataFile)) { Serializer.Serialize(outputStream, QueueList); } } [Serializable] [ProtoContract] public class QueueList : SafeList<QueueItem> { } [Serializable] [ProtoContract]

Parsing a raw Protocol Buffer byte stream in C#

∥☆過路亽.° 提交于 2019-12-21 20:26:48
问题 Given a protocol buffer encoded Stream or byte[] but NOT knowing the object type itself, how can we print the skeleton of the message? The use case is for debugging IO that's protobuf based, for root cause analysis. If there are existing tools that can parse the raw Protocol Buffer byte stream from a binary file - that would be great! An alternative could be using the ProtoBuf.NET class ProtoReader() to keep chugging along till we hit the error but the usage of ProtoReader() isn't clear. I