DecodeZigZag32() static private method

Decode a 32-bit value with ZigZag encoding.
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.)
static private DecodeZigZag32 ( uint n ) : int
n uint
return int
Beispiel #1
0
 public void RoundTripZigZag32()
 {
     // Some easier-to-verify round-trip tests.  The inputs (other than 0, 1, -1)
     // were chosen semi-randomly via keyboard bashing.
     Assert.AreEqual(0, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(0)));
     Assert.AreEqual(1, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(1)));
     Assert.AreEqual(-1, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-1)));
     Assert.AreEqual(14927, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(14927)));
     Assert.AreEqual(-3612, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-3612)));
 }
 public void DecodeZigZag32()
 {
     Assert.AreEqual(0, CodedInputStream.DecodeZigZag32(0));
     Assert.AreEqual(-1, CodedInputStream.DecodeZigZag32(1));
     Assert.AreEqual(1, CodedInputStream.DecodeZigZag32(2));
     Assert.AreEqual(-2, CodedInputStream.DecodeZigZag32(3));
     Assert.AreEqual(0x3FFFFFFF, CodedInputStream.DecodeZigZag32(0x7FFFFFFE));
     Assert.AreEqual(unchecked ((int)0xC0000000), CodedInputStream.DecodeZigZag32(0x7FFFFFFF));
     Assert.AreEqual(0x7FFFFFFF, CodedInputStream.DecodeZigZag32(0xFFFFFFFE));
     Assert.AreEqual(unchecked ((int)0x80000000), CodedInputStream.DecodeZigZag32(0xFFFFFFFF));
 }