EncodeZigZag64() статический приватный Метод

Encode a 64-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 EncodeZigZag64 ( long n ) : ulong
n long
Результат ulong
Пример #1
0
        public void RoundTripZigZag64()
        {
            Assert.AreEqual(0, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(0)));
            Assert.AreEqual(1, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(1)));
            Assert.AreEqual(-1, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-1)));
            Assert.AreEqual(14927, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(14927)));
            Assert.AreEqual(-3612, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-3612)));

            Assert.AreEqual(856912304801416L,
                            CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(856912304801416L)));
            Assert.AreEqual(-75123905439571256L,
                            CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-75123905439571256L)));
        }
Пример #2
0
 public void EncodeZigZag64()
 {
     Assert.AreEqual(0u, CodedOutputStream.EncodeZigZag64(0));
     Assert.AreEqual(1u, CodedOutputStream.EncodeZigZag64(-1));
     Assert.AreEqual(2u, CodedOutputStream.EncodeZigZag64(1));
     Assert.AreEqual(3u, CodedOutputStream.EncodeZigZag64(-2));
     Assert.AreEqual(0x000000007FFFFFFEuL,
                     CodedOutputStream.EncodeZigZag64(unchecked ((long)0x000000003FFFFFFFUL)));
     Assert.AreEqual(0x000000007FFFFFFFuL,
                     CodedOutputStream.EncodeZigZag64(unchecked ((long)0xFFFFFFFFC0000000UL)));
     Assert.AreEqual(0x00000000FFFFFFFEuL,
                     CodedOutputStream.EncodeZigZag64(unchecked ((long)0x000000007FFFFFFFUL)));
     Assert.AreEqual(0x00000000FFFFFFFFuL,
                     CodedOutputStream.EncodeZigZag64(unchecked ((long)0xFFFFFFFF80000000UL)));
     Assert.AreEqual(0xFFFFFFFFFFFFFFFEL,
                     CodedOutputStream.EncodeZigZag64(unchecked ((long)0x7FFFFFFFFFFFFFFFUL)));
     Assert.AreEqual(0xFFFFFFFFFFFFFFFFL,
                     CodedOutputStream.EncodeZigZag64(unchecked ((long)0x8000000000000000UL)));
 }
Пример #3
0
 public void WriteSInt64(long value)
 {
     this.WriteRawVarint64(CodedOutputStream.EncodeZigZag64(value));
 }
Пример #4
0
 public static int ComputeSInt64Size(long value)
 {
     return(CodedOutputStream.ComputeRawVarint64Size(CodedOutputStream.EncodeZigZag64(value)));
 }