From 39aaf21d5194fdc07c296847def8e7795279e041 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Thu, 11 Jun 2015 21:15:36 +0100 Subject: Reimplement enums as int values, and get rid of EnumHelper. This makes repeated fields really awkward at the moment - but when we reimplement RepeatedField to be backed by an array, we can cast the array directly... --- csharp/src/ProtocolBuffers/CodedInputStream.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'csharp/src/ProtocolBuffers/CodedInputStream.cs') diff --git a/csharp/src/ProtocolBuffers/CodedInputStream.cs b/csharp/src/ProtocolBuffers/CodedInputStream.cs index 685d7702..d5cab6fd 100644 --- a/csharp/src/ProtocolBuffers/CodedInputStream.cs +++ b/csharp/src/ProtocolBuffers/CodedInputStream.cs @@ -434,11 +434,10 @@ namespace Google.Protobuf /// then the ref value is set and it returns true. Otherwise the unknown output /// value is set and this method returns false. /// - public bool ReadEnum(ref T value) - where T : struct, IComparable, IFormattable + public bool ReadEnum(ref int value) { - int number = (int) ReadRawVarint32(); - value = EnumHelper.FromInt32(number); + // Currently just a pass-through, but it's nice to separate it logically from WriteInt32. + value = (int) ReadRawVarint32(); return true; } @@ -796,7 +795,7 @@ namespace Google.Protobuf public void ReadEnumArray(uint fieldTag, string fieldName, ICollection list) where T : struct, IComparable, IFormattable { - T value = default(T); + int value = 0; WireFormat.WireType wformat = WireFormat.GetTagWireType(fieldTag); // 2.3 allows packed form even if the field is not declared packed. @@ -806,8 +805,9 @@ namespace Google.Protobuf int limit = PushLimit(length); while (!ReachedLimit) { - ReadEnum(ref value); - list.Add(value); + ReadEnum(ref value); + // TODO(jonskeet): Avoid this horrible boxing! + list.Add((T)(object)value); } PopLimit(limit); } @@ -816,7 +816,8 @@ namespace Google.Protobuf do { ReadEnum(ref value); - list.Add(value); + // TODO(jonskeet): Avoid this horrible boxing! + list.Add((T)(object) value); } while (ContinueArray(fieldTag)); } } -- cgit v1.2.3