protobuf-net

Protobuf-net and Unity3D types

岁酱吖の 提交于 2019-12-24 04:42:13
问题 I have question about protobuf-net in Unity3d. Is it possible to serialize unity3d types: GameObject. Example, I have in class property with type GameObject, this class serializedd/deserialized? using ProtoBuf; using UnityEngine; ... [ProtoContract] public class Example { [ProtoMember(1)] public int Count {get;set;} [ProtoMember(2)] public string Name {get;set;} [ProtoMember(3)] public GameObject MyGameObject {get;set;} // ??? } Sorry, my english.. 回答1: You have to tell protobuf-net which

protobuf-net UseImplicitZeroDefaults and Enum defaults

南楼画角 提交于 2019-12-24 02:28:11
问题 We're trying to use protobuf-net but having trouble understanding UseImplicitZeroDefaults which we now disable in a custom RuntimeTypeModel. We initially used the default RuntimeTypeModel but noticed boolean properties were not being cloned even though a DefaultValue was being specified, i.e. DefaultValue=true but when set to false the cloned property would always be true. We resolved this by creating a custom RuntimeTypeModel which has allowed us to set UseImplicitZeroDefaults to false. But

protobuf-net UseImplicitZeroDefaults and Enum defaults

自作多情 提交于 2019-12-24 02:28:06
问题 We're trying to use protobuf-net but having trouble understanding UseImplicitZeroDefaults which we now disable in a custom RuntimeTypeModel. We initially used the default RuntimeTypeModel but noticed boolean properties were not being cloned even though a DefaultValue was being specified, i.e. DefaultValue=true but when set to false the cloned property would always be true. We resolved this by creating a custom RuntimeTypeModel which has allowed us to set UseImplicitZeroDefaults to false. But

Mimic ProtoEnumAttribute with ProtoBuf.Meta interface

情到浓时终转凉″ 提交于 2019-12-24 02:08:04
问题 In protobuf-net, you can override the wire format for enumerations with the ProtoEnumAttribute like so: [ProtoContract] enum MyEnum { [ProtoEnum(Value=1)] Default, [ProtoEnum(Value=10)] Foo } With those attributes, where Default would normally serialize to 0 and Foo to 1 they will now serialize to 1 and 10 respectively. What I'm trying to do is mimic this behavior using interfaces in ProtoBuf.Meta, so I don't have to annotate enumerations (because I don't typically control them in my project)

I cannot deserialize data previously serialized successfully

跟風遠走 提交于 2019-12-24 02:07:36
问题 I was randomly typing 'fastest serializing c#' into Google and got protobuf.net as a result. I tried it and I think I can serialize properly yet since I can't deserilize, there is no way to tell now is there?! When trying to deserilaize I get : A first chance exception of type 'ProtoBuf.ProtoException' occurred in protobuf-net.dll Cool. The Data To Serialize: [ProtoContract] public struct Cow { [ProtoMember(1)] public float Weight{ get; private set; } [ProtoMember(2)] public bool[]

Protobuf-net skip deserialization of specific fields

蹲街弑〆低调 提交于 2019-12-24 00:57:33
问题 I have serialized this class: [ProtoContract] public class TestClass { [ProtoMember(1)] public int[] hugeArray; [ProtoMember(2)] public int x; [ProtoMember(3)] public int y; //lot more fields and properties to serialize here... } How do I skip the [ProtoMember(1)] hugeArray during deserialization, so that only x, y, and other fields get deserialized? My problem is that sometimes I quickly need only to get the 'metadata', which is what other fields and properties describe, but sometimes I need

c# protobuf-net when deserialize the some property value always is -1

浪子不回头ぞ 提交于 2019-12-23 20:26:14
问题 i'm not sure this problem whether is the bug or it's just this,before i can't noticed this. i create a Document class and declare the protobuf-net restrict. [ProtoContract] public class Document { [ProtoMember(1)] private Dictionary<string,string> _items; [ProtoMember(2)] public int DocNumber { get; set; } public Document() { this.DocNumber = -1; this._items = new Dictionary<string,string>(); } public byte[] Serialize() { byte[] bytes = null; using (var ms = new MemoryStream()) { Serializer

protobuf-net and serializing a linked list using interfaces

守給你的承諾、 提交于 2019-12-23 20:14:36
问题 I have come across a problem with protobuf-net and have narrowed it down to this simplest case. I want a linked list type structure, where a class has a property of the same type. When I serialize this it works great. However if the type is an interface instead of a class I get the following error: The type cannot be changed once a serializer has been generated for ConsoleApplication1.foo (ConsoleApplication1.ifoo) This is the code I have to generate this error: class Program { static void

What's the .proto equivalent of List<T> in protobuf-net?

点点圈 提交于 2019-12-23 20:07:08
问题 To keep some consistency, we use code generation for a lot of our object models, and one of the offshoots of that has been generating the .proto files for ProtocolBuffers via a separate generation module. At this point though, I'm stumped at how to implement the generation for when it happens upon a List<T> object. It looks like this is possible via contracts: [ProtoMember(1)] public List<SomeType> MyList {get; set;} but outside of that, I'm not sure how or if it's possible to do this only

No serializer defined for type: System.Drawing.Color

冷暖自知 提交于 2019-12-23 17:16:42
问题 In order to decrease the network traffic, I want to use protobuf-net to instead of the BinaryFormatter , But the following error happened: No serializer defined for type: System.Drawing.Color WBMessage: [ProtoContract] [Serializable] public abstract class WBMessage { [ProtoMember(1)] public Color setColor1; [ProtoMember(2)] public UInt16 userNo; public abstract WHITEBOARD_MESSAGE_TYPE MessageType { get; } [ProtoMember(3)] public string age; public enum WHITEBOARD_MESSAGE_TYPE { enWBBegin,