Open GoogleCodeExporter opened 9 years ago
Interesting. The implicit default value is (by protobuf rules) the first enum
value (IDENTIFICATION), so this is odd; I wonder if the existing detectMissing
switch might help?
Original comment by marc.gravell
on 8 Aug 2011 at 10:04
I have similar situation (C#).
Have very simple enum and class:
[ProtoContract(ImplicitFields = ImplicitFields.AllPublic)]
public class FullVehicleDummy : VehicleDummy
{
private ConnectionState connectionState = ConnectionState.Disconnected;
[DefaultValue(ConnectionState.Disconnected)]
public ConnectionState ConnectionState
{
get { return connectionState; }
set { connectionState = value; }
}
}
public enum ConnectionState
{
Connected,
Disconnected,
SuperConected,
NotConected
}
ConnectionState property works well only with DefaultValue attribute. In other
case it seems that protobuf doesn't serialize/deserialize it properly.
Used 2.0.0.621 version of protobuf-net.dll.
Original comment by aldoshki...@gmail.com
on 26 Sep 2013 at 12:27
Yes, noted. This is the implicit zero default behaviour. If I was designing the
library from scratch, I probably would have made this work differently. As it
is currently, to preserve backwards compatibility, you can change this *for
custom models*, by setting
model.UseImplicitZeroDefaults = false;
(and using that model rather than Serializer.Serialize / Serializer.Deserialize)
Alternatively, you can use [DefaultValue(...)] (as noted), or (when a
[ProtoMember] is present): IsRequired=true
Original comment by marc.gravell
on 26 Sep 2013 at 12:47
Marc, thank you for quick answer, will use your advice.
Original comment by aldoshki...@gmail.com
on 26 Sep 2013 at 12:53
Original issue reported on code.google.com by
slawek.m...@gmail.com
on 7 Aug 2011 at 10:51