mmo87077 / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

Incompatibility between Protobuf-net and Protobuf-csharp-port #258

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Kris.VanHoye@Avalon-automation.be
==============
InvalidProtocolBufferException was unhandled
Message missing required fields: Childs[1].ValueBool
==============
We try to communicate via C# Protobuf-net lib to an Objective-C app that use 
the Protobuf serialization. The problem we have is that the current version 
(V2475) in our POC is not compatible. We miss to bytes with the Protobuf.net 
lib.
I added a really small test project to this Issue.
Hopefully you can find some time to look to it because I prefer your lib.

Greetings,
KVH

Original issue reported on code.google.com by kris.van...@Avalon-automation.be on 7 Dec 2011 at 8:46

Attachments:

GoogleCodeExporter commented 9 years ago
This is due to a subtle difference in the processing of default values, and how 
protobuf-net decides whether or not to include a value. In this case, the 
simplest behaviour is to ask it to always include `ValueBool` explicitly:

    [ProtoMember(2, IsRequired = true)]

(in 2 places, IIRC)

There are a number of ways of deciding the conditional serialization rules in 
protobuf-net, including:

- Nullable<bool>
- ShouldSerialize{PropertyName} (pattern from XmlSerializer and ComponentModel)
- {PropertyName}Specified (pattern from XmlSerializer)

it can *also* be influenced by [DefaultValue(...)], and in v2 the implicit 
defaults can be disabled if desired.

But: adding IsRequired fixes it in your example.

Original comment by marc.gravell on 7 Dec 2011 at 3:50