Support packed primitive types
diff --git a/src/ProtocolBuffers/WireFormat.cs b/src/ProtocolBuffers/WireFormat.cs
index abf4716..2bd0a5a 100644
--- a/src/ProtocolBuffers/WireFormat.cs
+++ b/src/ProtocolBuffers/WireFormat.cs
@@ -46,6 +46,19 @@
/// </para>
/// </summary>
public static class WireFormat {
+
+#region Fixed sizes.
+ // TODO(jonskeet): Move these somewhere else. They're messy. Consider making FieldType a smarter kind of enum
+ internal const int Fixed32Size = 4;
+ internal const int Fixed64Size = 8;
+ internal const int SFixed32Size = 4;
+ internal const int SFixed64Size = 8;
+ internal const int FloatSize = 4;
+ internal const int DoubleSize = 8;
+ internal const int BoolSize = 1;
+#endregion
+
+
public enum WireType : uint {
Varint = 0,
Fixed64 = 1,
@@ -93,6 +106,18 @@
return (uint) (fieldNumber << TagTypeBits) | (uint) wireType;
}
+ public static uint MakeTag(FieldDescriptor field) {
+ return MakeTag(field.FieldNumber, GetWireType(field));
+ }
+
+ /// <summary>
+ /// Returns the wire type for the given field descriptor. This differs
+ /// from GetWireType(FieldType) for packed repeated fields.
+ /// </summary>
+ internal static WireType GetWireType(FieldDescriptor descriptor) {
+ return descriptor.IsPacked ? WireType.LengthDelimited : GetWireType(descriptor.FieldType);
+ }
+
/// <summary>
/// Converts a field type to its wire type. Done with a switch for the sake
/// of speed - this is significantly faster than a dictionary lookup.