aboutsummaryrefslogtreecommitdiff
path: root/src/ProtocolBuffers/WireFormat.cs
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2011-05-20 15:15:34 -0500
committerrogerk <devnull@localhost>2011-05-20 15:15:34 -0500
commit71f662c33e9938951eec3da97140aed25aa815d7 (patch)
treec322e13686cad5c8bff9e54d7585fc8e4adf6537 /src/ProtocolBuffers/WireFormat.cs
parentd965c666ecf405f4e997ab251e72551508a14678 (diff)
downloadprotobuf-71f662c33e9938951eec3da97140aed25aa815d7.tar.gz
protobuf-71f662c33e9938951eec3da97140aed25aa815d7.tar.bz2
protobuf-71f662c33e9938951eec3da97140aed25aa815d7.zip
reformatted all code to .NET standard formatting
Diffstat (limited to 'src/ProtocolBuffers/WireFormat.cs')
-rw-r--r--src/ProtocolBuffers/WireFormat.cs271
1 files changed, 144 insertions, 127 deletions
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 {
-
- /// <summary>
- /// 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.
- /// <para>
- /// This class contains constants and helper functions useful for dealing with
- /// the Protocol Buffer wire format.
- /// </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
- 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
+{
+ /// <summary>
+ /// 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.
+ /// <para>
+ /// This class contains constants and helper functions useful for dealing with
+ /// the Protocol Buffer wire format.
+ /// </para>
+ /// </summary>
+ 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
+ }
- /// <summary>
- /// Given a tag value, determines the wire type (lower 3 bits).
- /// </summary>
- [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);
+ }
- /// <summary>
- /// Given a tag value, determines the field number (the upper 29 bits).
- /// </summary>
- [CLSCompliant(false)]
- public static int GetTagFieldNumber(uint tag) {
- return (int) tag >> TagTypeBits;
- }
+ private const int TagTypeBits = 3;
+ private const uint TagTypeMask = (1 << TagTypeBits) - 1;
- /// <summary>
- /// Makes a tag value given a field number and wire type.
- /// TODO(jonskeet): Should we just have a Tag structure?
- /// </summary>
- [CLSCompliant(false)]
- public static uint MakeTag(int fieldNumber, WireType wireType) {
- return (uint) (fieldNumber << TagTypeBits) | (uint) wireType;
- }
+ /// <summary>
+ /// Given a tag value, determines the wire type (lower 3 bits).
+ /// </summary>
+ [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;
+ }
+
+ /// <summary>
+ /// Given a tag value, determines the field number (the upper 29 bits).
+ /// </summary>
+ [CLSCompliant(false)]
+ public static int GetTagFieldNumber(uint tag)
+ {
+ return (int) tag >> TagTypeBits;
+ }
+
+ /// <summary>
+ /// Makes a tag value given a field number and wire type.
+ /// TODO(jonskeet): Should we just have a Tag structure?
+ /// </summary>
+ [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));
+ }
- /// <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>
+ /// 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.
- /// </summary>
- [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");
- }
- }
+ /// <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.
+ /// </summary>
+ [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