1 #region Copyright notice and license
\r
2 // Protocol Buffers - Google's data interchange format
\r
3 // Copyright 2008 Google Inc. All rights reserved.
\r
4 // https://developers.google.com/protocol-buffers/
\r
6 // Redistribution and use in source and binary forms, with or without
\r
7 // modification, are permitted provided that the following conditions are
\r
10 // * Redistributions of source code must retain the above copyright
\r
11 // notice, this list of conditions and the following disclaimer.
\r
12 // * Redistributions in binary form must reproduce the above
\r
13 // copyright notice, this list of conditions and the following disclaimer
\r
14 // in the documentation and/or other materials provided with the
\r
16 // * Neither the name of Google Inc. nor the names of its
\r
17 // contributors may be used to endorse or promote products derived from
\r
18 // this software without specific prior written permission.
\r
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
\r
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
\r
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
\r
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
\r
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
\r
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
\r
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
\r
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
33 namespace Google.Protobuf
\r
36 /// This class is used internally by the Protocol Buffer Library and generated
\r
37 /// message implementations. It is public only for the sake of those generated
\r
38 /// messages. Others should not use this class directly.
\r
40 /// This class contains constants and helper functions useful for dealing with
\r
41 /// the Protocol Buffer wire format.
\r
44 public static class WireFormat
\r
47 /// Wire types within protobuf encoding.
\r
49 public enum WireType : uint
\r
52 /// Variable-length integer.
\r
56 /// A fixed-length 64-bit value.
\r
60 /// A length-delimited value, i.e. a length followed by that many bytes of data.
\r
62 LengthDelimited = 2,
\r
64 /// A "start group" value
\r
68 /// An "end group" value
\r
72 /// A fixed-length 32-bit value.
\r
77 private const int TagTypeBits = 3;
\r
78 private const uint TagTypeMask = (1 << TagTypeBits) - 1;
\r
81 /// Given a tag value, determines the wire type (lower 3 bits).
\r
83 public static WireType GetTagWireType(uint tag)
\r
85 return (WireType) (tag & TagTypeMask);
\r
89 /// Given a tag value, determines the field number (the upper 29 bits).
\r
91 public static int GetTagFieldNumber(uint tag)
\r
93 return (int) tag >> TagTypeBits;
\r
97 /// Makes a tag value given a field number and wire type.
\r
99 public static uint MakeTag(int fieldNumber, WireType wireType)
\r
101 return (uint) (fieldNumber << TagTypeBits) | (uint) wireType;
\r