protobuf-net

How to append object to a file while serializing using c# protobuf-net?

試著忘記壹切 提交于 2020-03-02 06:57:12
问题 I got a source code of Protobuf-net that serializes an object to a file. var person = new Person { Id = 12345, Name = "Fred", Address = new Address { Line1 = "Flat 1", Line2 = "The Meadows" } }; using (var file = File.Create("person.bin")) { ProtoBuf.Serializer.Serialize(file, person); } But suppose i have two instance of Person that i want to serialize into a single file. how can i do that? 回答1: protobuf, in the pure sense, does not have any "terminator" except the end of a file (this is so

Protocol buffers detect type from raw message

最后都变了- 提交于 2020-02-17 13:36:12
问题 Is it possible to detect the type of a raw protocol buffer message (in byte[]) I have a situation where an endpoint can receive different messages and I need to be able to detect the type before I can deserialize it. I am using protobuf-net 回答1: You can't detect the type in isolation, since the protobuf spec doesn't add any data to the stream for this; however, there are a number of ways of making this easy, depending on the context: a union type (as mentioned by Jon) covers a range of

Protocol buffers detect type from raw message

佐手、 提交于 2020-02-17 13:34:30
问题 Is it possible to detect the type of a raw protocol buffer message (in byte[]) I have a situation where an endpoint can receive different messages and I need to be able to detect the type before I can deserialize it. I am using protobuf-net 回答1: You can't detect the type in isolation, since the protobuf spec doesn't add any data to the stream for this; however, there are a number of ways of making this easy, depending on the context: a union type (as mentioned by Jon) covers a range of

Protocol buffers detect type from raw message

£可爱£侵袭症+ 提交于 2020-02-17 13:32:36
问题 Is it possible to detect the type of a raw protocol buffer message (in byte[]) I have a situation where an endpoint can receive different messages and I need to be able to detect the type before I can deserialize it. I am using protobuf-net 回答1: You can't detect the type in isolation, since the protobuf spec doesn't add any data to the stream for this; however, there are a number of ways of making this easy, depending on the context: a union type (as mentioned by Jon) covers a range of

Protocol buffers detect type from raw message

二次信任 提交于 2020-02-17 13:32:00
问题 Is it possible to detect the type of a raw protocol buffer message (in byte[]) I have a situation where an endpoint can receive different messages and I need to be able to detect the type before I can deserialize it. I am using protobuf-net 回答1: You can't detect the type in isolation, since the protobuf spec doesn't add any data to the stream for this; however, there are a number of ways of making this easy, depending on the context: a union type (as mentioned by Jon) covers a range of

Creating MVC3 ValueProviderFactories That Require Type Information?

坚强是说给别人听的谎言 提交于 2020-01-23 12:05:37
问题 I'm attempting to write a Protobuf ValueProviderFactory for ASP MVC3. I've managed to work out how to add the factories, but now I've stumbled on a more pressing problem. Here is where the current serialization takes place in JsonValueProviderFactory.cs JavaScriptSerializer serializer = new JavaScriptSerializer(); object jsonData = serializer.DeserializeObject(bodyText); return jsonData; So the deserialization is accomplished without any type information? What sort of object does

What is protobuf-net SerializeWithLengthPrefix tag argument for?

懵懂的女人 提交于 2020-01-21 01:37:28
问题 This method accepts as the last argument an integer, but I'm not sure I understand what I would use it for exactly. Serializer.SerializeWithLengthPrefix(stream, object, PrefixStyle.Base128, [tag]); The same holds true for the corresponding Deserialize method. Is it just a way to tag messages to add some sort of "querying" capabilities on deserialization to filter out unwanted messages or does it have any other usages? 回答1: Basically, it is an additional marker that can be (although does not

Stubborn object won't serialize with protobuf-net

♀尐吖头ヾ 提交于 2020-01-16 05:21:07
问题 I'm integrating protobuf-net into our WCF services based solution but have ran into a snag that I can't figure out. The following class will serialize fine, all except for the ObjectId property. /// <summary> /// A service data object that represents a user of the system. /// </summary> [DataContract(Namespace = "http://LINKS.Service.Security.Administration", Name = "User")] public sealed class UserMessagePart : IMessagePart { private ObjectId objectId; private string userName; private string

Serialize inherited classes using protobuf-net

血红的双手。 提交于 2020-01-15 05:58:29
问题 I have a problem serializing derived classes using protobuf-net. I don't know if it is because it is not supported, or I am doing something wrong. I have a generic base class (which I can serialize directly) and then i make a specialization of this, but this one I can't serialize. The following is the code for the two classes and a example of usage. Am i doing something wrong? Edit Added restriction to the generic types Base [ProtoBuf.ProtoContract] public class Base<TKey, TValue> where TKey

Open OSM pbf results in Protobuf exception

馋奶兔 提交于 2020-01-15 03:16:07
问题 Using OSMSharp I am having trouble to open a stream for a file (which I can provide on demand) The error occurs in PBFReader (line 104) using (var tmp = new LimitedStream(_stream, length)) { header = _runtimeTypeModel.Deserialize(tmp, null, _blockHeaderType) as BlobHeader; } and states: "ProtoBuf.ProtoException: 'Invalid field in source data: 0'" which might mean different things as I have read in this SO question. The file opens and is visualized with QGis so is not corrupt in my opinion.