From 811fc89f0eb036d95653f5fed4b0ffea292ce791 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Tue, 4 Aug 2015 15:58:39 +0100 Subject: Document everything, and turn on errors if we fail to document anything in the future. --- csharp/src/Google.Protobuf/WireFormat.cs | 89 ++++++++++---------------------- 1 file changed, 27 insertions(+), 62 deletions(-) (limited to 'csharp/src/Google.Protobuf/WireFormat.cs') diff --git a/csharp/src/Google.Protobuf/WireFormat.cs b/csharp/src/Google.Protobuf/WireFormat.cs index c1712daa..bbd7e4f9 100644 --- a/csharp/src/Google.Protobuf/WireFormat.cs +++ b/csharp/src/Google.Protobuf/WireFormat.cs @@ -30,9 +30,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion -using System; -using Google.Protobuf.Reflection; - namespace Google.Protobuf { /// @@ -59,13 +56,34 @@ namespace Google.Protobuf #endregion + /// + /// Wire types within protobuf encoding. + /// public enum WireType : uint { + /// + /// Variable-length integer. + /// Varint = 0, + /// + /// A fixed-length 64-bit value. + /// Fixed64 = 1, + /// + /// A length-delimited value, i.e. a length followed by that many bytes of data. + /// LengthDelimited = 2, + /// + /// A "start group" value - not supported by this implementation. + /// StartGroup = 3, + /// + /// An "end group" value - not supported by this implementation. + /// EndGroup = 4, + /// + /// A fixed-length 32-bit value. + /// Fixed32 = 5 } @@ -80,6 +98,11 @@ namespace Google.Protobuf return (WireType) (tag & TagTypeMask); } + /// + /// Determines whether the given tag is an end group tag. + /// + /// The tag to check. + /// true if the given tag is an end group tag; false otherwise. public static bool IsEndGroupTag(uint tag) { return (WireType) (tag & TagTypeMask) == WireType.EndGroup; @@ -99,64 +122,6 @@ namespace Google.Protobuf public static uint MakeTag(int fieldNumber, WireType wireType) { return (uint) (fieldNumber << TagTypeBits) | (uint) wireType; - } - - public static uint MakeTag(FieldDescriptor field) - { - return MakeTag(field.FieldNumber, GetWireType(field)); - } - - /// - /// Returns the wire type for the given field descriptor. This differs - /// from GetWireType(FieldType) for packed repeated fields. - /// - internal static WireType GetWireType(FieldDescriptor descriptor) - { - return descriptor.IsPacked ? WireType.LengthDelimited : GetWireType(descriptor.FieldType); - } - - /// - /// 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. - /// - public static WireType GetWireType(FieldType fieldType) - { - switch (fieldType) - { - case FieldType.Double: - return WireType.Fixed64; - case FieldType.Float: - return WireType.Fixed32; - case FieldType.Int64: - case FieldType.UInt64: - case FieldType.Int32: - return WireType.Varint; - case FieldType.Fixed64: - return WireType.Fixed64; - case FieldType.Fixed32: - return WireType.Fixed32; - case FieldType.Bool: - return WireType.Varint; - case FieldType.String: - return WireType.LengthDelimited; - case FieldType.Group: - return WireType.StartGroup; - case FieldType.Message: - case FieldType.Bytes: - return WireType.LengthDelimited; - case FieldType.UInt32: - return WireType.Varint; - case FieldType.SFixed32: - return WireType.Fixed32; - case FieldType.SFixed64: - return WireType.Fixed64; - case FieldType.SInt32: - case FieldType.SInt64: - case FieldType.Enum: - return WireType.Varint; - default: - throw new ArgumentOutOfRangeException("fieldType", "No such field type"); - } - } + } } } \ No newline at end of file -- cgit v1.2.3