aboutsummaryrefslogtreecommitdiff
path: root/csharp/ProtocolBuffers/CodedInputStream.cs
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/ProtocolBuffers/CodedInputStream.cs')
-rw-r--r--csharp/ProtocolBuffers/CodedInputStream.cs31
1 files changed, 31 insertions, 0 deletions
diff --git a/csharp/ProtocolBuffers/CodedInputStream.cs b/csharp/ProtocolBuffers/CodedInputStream.cs
new file mode 100644
index 00000000..66dae52c
--- /dev/null
+++ b/csharp/ProtocolBuffers/CodedInputStream.cs
@@ -0,0 +1,31 @@
+
+namespace Google.ProtocolBuffers {
+ public sealed class CodedInputStream {
+
+ /// <summary>
+ /// Decode a 32-bit value with ZigZag encoding.
+ /// </summary>
+ /// <remarks>
+ /// ZigZag encodes signed integers into values that can be efficiently
+ /// encoded with varint. (Otherwise, negative values must be
+ /// sign-extended to 64 bits to be varint encoded, thus always taking
+ /// 10 bytes on the wire.)
+ /// </remarks>
+ public static int DecodeZigZag32(uint n) {
+ return (int)(n >> 1) ^ -(int)(n & 1);
+ }
+
+ /// <summary>
+ /// Decode a 32-bit value with ZigZag encoding.
+ /// </summary>
+ /// <remarks>
+ /// ZigZag encodes signed integers into values that can be efficiently
+ /// encoded with varint. (Otherwise, negative values must be
+ /// sign-extended to 64 bits to be varint encoded, thus always taking
+ /// 10 bytes on the wire.)
+ /// </remarks>
+ public static long DecodeZigZag64(ulong n) {
+ return (long)(n >> 1) ^ -(long)(n & 1);
+ }
+ }
+}