aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers/FieldCodec.cs
diff options
context:
space:
mode:
authorJon Skeet <jonskeet@google.com>2015-07-17 06:41:46 +0100
committerJon Skeet <jonskeet@google.com>2015-07-17 06:41:46 +0100
commit34878cb14eba4578d1d67d2dc93250729d492774 (patch)
tree6764c5a6f20e7ac4f2c7205638222d7cbbe4a90f /csharp/src/ProtocolBuffers/FieldCodec.cs
parent3da90e9f54f9648a76a0172e5af94f4a0a00a5e8 (diff)
downloadprotobuf-34878cb14eba4578d1d67d2dc93250729d492774.tar.gz
protobuf-34878cb14eba4578d1d67d2dc93250729d492774.tar.bz2
protobuf-34878cb14eba4578d1d67d2dc93250729d492774.zip
Fixes from PR review.
Diffstat (limited to 'csharp/src/ProtocolBuffers/FieldCodec.cs')
-rw-r--r--csharp/src/ProtocolBuffers/FieldCodec.cs30
1 files changed, 20 insertions, 10 deletions
diff --git a/csharp/src/ProtocolBuffers/FieldCodec.cs b/csharp/src/ProtocolBuffers/FieldCodec.cs
index caf03286..85462787 100644
--- a/csharp/src/ProtocolBuffers/FieldCodec.cs
+++ b/csharp/src/ProtocolBuffers/FieldCodec.cs
@@ -161,20 +161,30 @@ namespace Google.Protobuf
null); // Default value for the wrapper
}
- // Helper code to create codecs for wrapper types. Somewhat ugly with all the
+ /// <summary>
+ /// Helper code to create codecs for wrapper types.
+ /// </summary>
+ /// <remarks>
+ /// Somewhat ugly with all the static methods, but the conversions involved to/from nullable types make it
+ /// slightly tricky to improve. So long as we keep the public API (ForClassWrapper, ForStructWrapper) in place,
+ /// we can refactor later if we come up with something cleaner.
+ /// </remarks>
private static class WrapperCodecs
{
+ // All the field numbers are the same (1).
+ private const int WrapperValueFieldNumber = Google.Protobuf.WellKnownTypes.Int32Value.ValueFieldNumber;
+
private static readonly Dictionary<Type, object> Codecs = new Dictionary<Type, object>
{
- { typeof(bool), ForBool(WireFormat.MakeTag(1, WireFormat.WireType.Varint)) },
- { typeof(int), ForInt32(WireFormat.MakeTag(1, WireFormat.WireType.Varint)) },
- { typeof(long), ForInt64(WireFormat.MakeTag(1, WireFormat.WireType.Varint)) },
- { typeof(uint), ForUInt32(WireFormat.MakeTag(1, WireFormat.WireType.Varint)) },
- { typeof(ulong), ForUInt64(WireFormat.MakeTag(1, WireFormat.WireType.Varint)) },
- { typeof(float), ForFloat(WireFormat.MakeTag(1, WireFormat.WireType.Fixed32)) },
- { typeof(double), ForDouble(WireFormat.MakeTag(1, WireFormat.WireType.Fixed64)) },
- { typeof(string), ForString(WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited)) },
- { typeof(ByteString), ForBytes(WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited)) }
+ { typeof(bool), ForBool(WireFormat.MakeTag(WrapperValueFieldNumber, WireFormat.WireType.Varint)) },
+ { typeof(int), ForInt32(WireFormat.MakeTag(WrapperValueFieldNumber, WireFormat.WireType.Varint)) },
+ { typeof(long), ForInt64(WireFormat.MakeTag(WrapperValueFieldNumber, WireFormat.WireType.Varint)) },
+ { typeof(uint), ForUInt32(WireFormat.MakeTag(WrapperValueFieldNumber, WireFormat.WireType.Varint)) },
+ { typeof(ulong), ForUInt64(WireFormat.MakeTag(WrapperValueFieldNumber, WireFormat.WireType.Varint)) },
+ { typeof(float), ForFloat(WireFormat.MakeTag(WrapperValueFieldNumber, WireFormat.WireType.Fixed32)) },
+ { typeof(double), ForDouble(WireFormat.MakeTag(WrapperValueFieldNumber, WireFormat.WireType.Fixed64)) },
+ { typeof(string), ForString(WireFormat.MakeTag(WrapperValueFieldNumber, WireFormat.WireType.LengthDelimited)) },
+ { typeof(ByteString), ForBytes(WireFormat.MakeTag(WrapperValueFieldNumber, WireFormat.WireType.LengthDelimited)) }
};
/// <summary>