From 71f662c33e9938951eec3da97140aed25aa815d7 Mon Sep 17 00:00:00 2001 From: csharptest Date: Fri, 20 May 2011 15:15:34 -0500 Subject: reformatted all code to .NET standard formatting --- src/ProtocolBuffers/WireFormat.cs | 271 ++++++++++++++++++++------------------ 1 file changed, 144 insertions(+), 127 deletions(-) (limited to 'src/ProtocolBuffers/WireFormat.cs') diff --git a/src/ProtocolBuffers/WireFormat.cs b/src/ProtocolBuffers/WireFormat.cs index 953364ad..53a5c826 100644 --- a/src/ProtocolBuffers/WireFormat.cs +++ b/src/ProtocolBuffers/WireFormat.cs @@ -1,4 +1,5 @@ #region Copyright notice and license + // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. // http://github.com/jskeet/dotnet-protobufs/ @@ -30,149 +31,165 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #endregion using System; + #if !LITE using Google.ProtocolBuffers.Descriptors; + #endif -namespace Google.ProtocolBuffers { - - /// - /// This class is used internally by the Protocol Buffer Library and generated - /// message implementations. It is public only for the sake of those generated - /// messages. Others should not use this class directly. - /// - /// This class contains constants and helper functions useful for dealing with - /// the Protocol Buffer wire format. - /// - /// - public static class WireFormat { - -#region Fixed sizes. - // TODO(jonskeet): Move these somewhere else. They're messy. Consider making FieldType a smarter kind of enum - public const int Fixed32Size = 4; - public const int Fixed64Size = 8; - public const int SFixed32Size = 4; - public const int SFixed64Size = 8; - public const int FloatSize = 4; - public const int DoubleSize = 8; - public const int BoolSize = 1; -#endregion +namespace Google.ProtocolBuffers +{ + /// + /// This class is used internally by the Protocol Buffer Library and generated + /// message implementations. It is public only for the sake of those generated + /// messages. Others should not use this class directly. + /// + /// This class contains constants and helper functions useful for dealing with + /// the Protocol Buffer wire format. + /// + /// + public static class WireFormat + { + #region Fixed sizes. - [CLSCompliant(false)] - public enum WireType : uint { - Varint = 0, - Fixed64 = 1, - LengthDelimited = 2, - StartGroup = 3, - EndGroup = 4, - Fixed32 = 5 - } + // TODO(jonskeet): Move these somewhere else. They're messy. Consider making FieldType a smarter kind of enum + public const int Fixed32Size = 4; + public const int Fixed64Size = 8; + public const int SFixed32Size = 4; + public const int SFixed64Size = 8; + public const int FloatSize = 4; + public const int DoubleSize = 8; + public const int BoolSize = 1; - internal static class MessageSetField { - internal const int Item = 1; - internal const int TypeID = 2; - internal const int Message = 3; - } + #endregion - internal static class MessageSetTag { - internal static readonly uint ItemStart = MakeTag(MessageSetField.Item, WireType.StartGroup); - internal static readonly uint ItemEnd = MakeTag(MessageSetField.Item, WireType.EndGroup); - internal static readonly uint TypeID = MakeTag(MessageSetField.TypeID, WireType.Varint); - internal static readonly uint Message = MakeTag(MessageSetField.Message, WireType.LengthDelimited); - } - - private const int TagTypeBits = 3; - private const uint TagTypeMask = (1 << TagTypeBits) - 1; + [CLSCompliant(false)] + public enum WireType : uint + { + Varint = 0, + Fixed64 = 1, + LengthDelimited = 2, + StartGroup = 3, + EndGroup = 4, + Fixed32 = 5 + } - /// - /// Given a tag value, determines the wire type (lower 3 bits). - /// - [CLSCompliant(false)] - public static WireType GetTagWireType(uint tag) { - return (WireType) (tag & TagTypeMask); - } + internal static class MessageSetField + { + internal const int Item = 1; + internal const int TypeID = 2; + internal const int Message = 3; + } - [CLSCompliant(false)] - public static bool IsEndGroupTag(uint tag) { - return (WireType)(tag & TagTypeMask) == WireType.EndGroup; - } + internal static class MessageSetTag + { + internal static readonly uint ItemStart = MakeTag(MessageSetField.Item, WireType.StartGroup); + internal static readonly uint ItemEnd = MakeTag(MessageSetField.Item, WireType.EndGroup); + internal static readonly uint TypeID = MakeTag(MessageSetField.TypeID, WireType.Varint); + internal static readonly uint Message = MakeTag(MessageSetField.Message, WireType.LengthDelimited); + } - /// - /// Given a tag value, determines the field number (the upper 29 bits). - /// - [CLSCompliant(false)] - public static int GetTagFieldNumber(uint tag) { - return (int) tag >> TagTypeBits; - } + private const int TagTypeBits = 3; + private const uint TagTypeMask = (1 << TagTypeBits) - 1; - /// - /// Makes a tag value given a field number and wire type. - /// TODO(jonskeet): Should we just have a Tag structure? - /// - [CLSCompliant(false)] - public static uint MakeTag(int fieldNumber, WireType wireType) { - return (uint) (fieldNumber << TagTypeBits) | (uint) wireType; - } + /// + /// Given a tag value, determines the wire type (lower 3 bits). + /// + [CLSCompliant(false)] + public static WireType GetTagWireType(uint tag) + { + return (WireType) (tag & TagTypeMask); + } + + [CLSCompliant(false)] + public static bool IsEndGroupTag(uint tag) + { + return (WireType) (tag & TagTypeMask) == WireType.EndGroup; + } + + /// + /// Given a tag value, determines the field number (the upper 29 bits). + /// + [CLSCompliant(false)] + public static int GetTagFieldNumber(uint tag) + { + return (int) tag >> TagTypeBits; + } + + /// + /// Makes a tag value given a field number and wire type. + /// TODO(jonskeet): Should we just have a Tag structure? + /// + [CLSCompliant(false)] + public static uint MakeTag(int fieldNumber, WireType wireType) + { + return (uint) (fieldNumber << TagTypeBits) | (uint) wireType; + } #if !LITE - [CLSCompliant(false)] - public static uint MakeTag(FieldDescriptor field) { - return MakeTag(field.FieldNumber, GetWireType(field)); - } + [CLSCompliant(false)] + 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); - } + /// + /// 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. - /// - [CLSCompliant(false)] - 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("No such field type"); - } - } + /// + /// 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. + /// + [CLSCompliant(false)] + 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("No such field type"); + } + } #endif - } -} + } +} \ No newline at end of file -- cgit v1.2.3