Open GoogleCodeExporter opened 9 years ago
I'm also seeing this invalid behaviour. An unknown enum value should be treated
like an unknown field or have it's default value set.
Original comment by felixbr...@gmail.com
on 27 Jan 2014 at 2:50
I looked at the code in an attempt to fix this for myself locally, and see in
the EnumSerializer.cs
public object Read(object value, ProtoReader source)
{
Helpers.DebugAssert(value == null); // since replaces
int wireValue = source.ReadInt32();
if(map == null) {
return WireToEnum(wireValue);
}
for(int i = 0 ; i < map.Length ; i++) {
if(map[i].WireValue == wireValue) {
return map[i].TypedValue;
}
}
source.ThrowEnumException(ExpectedType, wireValue);
return null; // to make compiler happy
}
Instead of throwing the enum exception at the end, it should just return null.
The level above it has a check for null and will assign the default value.
This works for me in debug versions, but i can't get the EnumSerializer to
compile in release, because i don't understand how the CompiledSerializer works.
Just my 2 cents on this in case it helps anyone identify the issue.
Original comment by chrisher...@gmail.com
on 30 Apr 2014 at 11:24
[deleted comment]
Thanks for proposed code, i can confirm it works! This is also how Java and C++
protobuffer handles undefined enums, that it will fallback to default value,
instead of throwing exception.
Original comment by noxx...@googlemail.com
on 30 May 2014 at 2:23
Original issue reported on code.google.com by
space...@yandex.ru
on 19 Dec 2013 at 9:51