aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers/CodedInputStream.cs
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2015-06-11 21:15:36 +0100
committerJon Skeet <skeet@pobox.com>2015-06-11 21:15:36 +0100
commit39aaf21d5194fdc07c296847def8e7795279e041 (patch)
tree174c362717574e13047c4d590b5f9609405aed84 /csharp/src/ProtocolBuffers/CodedInputStream.cs
parentce0e348ded9cb7e180588476ebb5a8f3e0460f4e (diff)
downloadprotobuf-39aaf21d5194fdc07c296847def8e7795279e041.tar.gz
protobuf-39aaf21d5194fdc07c296847def8e7795279e041.tar.bz2
protobuf-39aaf21d5194fdc07c296847def8e7795279e041.zip
Reimplement enums as int values, and get rid of EnumHelper.
This makes repeated fields really awkward at the moment - but when we reimplement RepeatedField<T> to be backed by an array, we can cast the array directly...
Diffstat (limited to 'csharp/src/ProtocolBuffers/CodedInputStream.cs')
-rw-r--r--csharp/src/ProtocolBuffers/CodedInputStream.cs17
1 files changed, 9 insertions, 8 deletions
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.
/// </summary>
- public bool ReadEnum<T>(ref T value)
- where T : struct, IComparable, IFormattable
+ public bool ReadEnum(ref int value)
{
- int number = (int) ReadRawVarint32();
- value = EnumHelper<T>.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<T>(uint fieldTag, string fieldName, ICollection<T> 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<T>(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));
}
}