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, ParsingPrimitives.DecodeZigZag32(WritingPrimitives.EncodeZigZag32(0))); Assert.AreEqual(1, ParsingPrimitives.DecodeZigZag32(WritingPrimitives.EncodeZigZag32(1))); Assert.AreEqual(-1, ParsingPrimitives.DecodeZigZag32(WritingPrimitives.EncodeZigZag32(-1))); Assert.AreEqual(14927, ParsingPrimitives.DecodeZigZag32(WritingPrimitives.EncodeZigZag32(14927))); Assert.AreEqual(-3612, ParsingPrimitives.DecodeZigZag32(WritingPrimitives.EncodeZigZag32(-3612))); }
public void DecodeZigZag32() { Assert.AreEqual(0, ParsingPrimitives.DecodeZigZag32(0)); Assert.AreEqual(-1, ParsingPrimitives.DecodeZigZag32(1)); Assert.AreEqual(1, ParsingPrimitives.DecodeZigZag32(2)); Assert.AreEqual(-2, ParsingPrimitives.DecodeZigZag32(3)); Assert.AreEqual(0x3FFFFFFF, ParsingPrimitives.DecodeZigZag32(0x7FFFFFFE)); Assert.AreEqual(unchecked ((int)0xC0000000), ParsingPrimitives.DecodeZigZag32(0x7FFFFFFF)); Assert.AreEqual(0x7FFFFFFF, ParsingPrimitives.DecodeZigZag32(0xFFFFFFFE)); Assert.AreEqual(unchecked ((int)0x80000000), ParsingPrimitives.DecodeZigZag32(0xFFFFFFFF)); }
/// <summary> /// Reads an sint32 field value from the stream. /// </summary> public int ReadSInt32() { return(ParsingPrimitives.DecodeZigZag32(ReadRawVarint32())); }
public int ReadSInt32() { return(ParsingPrimitives.DecodeZigZag32(ParsingPrimitives.ParseRawVarint32(ref buffer, ref state))); }