aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers
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
parent3da90e9f54f9648a76a0172e5af94f4a0a00a5e8 (diff)
downloadprotobuf-34878cb14eba4578d1d67d2dc93250729d492774.tar.gz
protobuf-34878cb14eba4578d1d67d2dc93250729d492774.tar.bz2
protobuf-34878cb14eba4578d1d67d2dc93250729d492774.zip
Fixes from PR review.
Diffstat (limited to 'csharp/src/ProtocolBuffers')
-rw-r--r--csharp/src/ProtocolBuffers/Collections/MapField.cs2
-rw-r--r--csharp/src/ProtocolBuffers/FieldCodec.cs30
2 files changed, 21 insertions, 11 deletions
diff --git a/csharp/src/ProtocolBuffers/Collections/MapField.cs b/csharp/src/ProtocolBuffers/Collections/MapField.cs
index ead45737..f5e4fd3a 100644
--- a/csharp/src/ProtocolBuffers/Collections/MapField.cs
+++ b/csharp/src/ProtocolBuffers/Collections/MapField.cs
@@ -51,7 +51,7 @@ namespace Google.Protobuf.Collections
public sealed class MapField<TKey, TValue> : IDeepCloneable<MapField<TKey, TValue>>, IFreezable, IDictionary<TKey, TValue>, IEquatable<MapField<TKey, TValue>>, IDictionary
{
// TODO: Don't create the map/list until we have an entry. (Assume many maps will be empty.)
- private bool allowNullValues;
+ private readonly bool allowNullValues;
private bool frozen;
private readonly Dictionary<TKey, LinkedListNode<KeyValuePair<TKey, TValue>>> map =
new Dictionary<TKey, LinkedListNode<KeyValuePair<TKey, TValue>>>();
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>