aboutsummaryrefslogtreecommitdiff
path: root/src/ProtocolBuffers/WireFormat.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ProtocolBuffers/WireFormat.cs')
-rw-r--r--src/ProtocolBuffers/WireFormat.cs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/ProtocolBuffers/WireFormat.cs b/src/ProtocolBuffers/WireFormat.cs
index abf47169..2bd0a5aa 100644
--- a/src/ProtocolBuffers/WireFormat.cs
+++ b/src/ProtocolBuffers/WireFormat.cs
@@ -46,6 +46,19 @@ namespace Google.ProtocolBuffers {
/// </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 @@ namespace Google.ProtocolBuffers {
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.