# HG changeset patch # User Ivo Smits # Date 1365550412 -7200 # Node ID 5d9a7186c9f7e9ea959a464db780c778af0e711a # Parent fba35b87da325ec0cea772665df9569425d3cd7f ProtocolBuffers: fix handling of 64 bit varint diff -r fba35b87da32 -r 5d9a7186c9f7 ProtocolBuffers.cs --- a/ProtocolBuffers.cs Sat Mar 30 16:41:14 2013 +0100 +++ b/ProtocolBuffers.cs Wed Apr 10 01:33:32 2013 +0200 @@ -67,13 +67,19 @@ } private int ReadVarIntTo(out int v) { + long vl; + int l = ReadVarIntTo(out vl); + v = (int)vl; + return l; + } + private int ReadVarIntTo(out long v) { v = 0; int h = 0; int b = 0x80; int l = 0; while ((b & 0x80) != 0) { b = buffer[offset + index + l]; - v |= (b & 0x7F) << h; + v |= ((long)b & 0x7FL) << h; h += 7; l++; } @@ -85,7 +91,7 @@ public long GetVarint() { if (!hasCurrentField || WireType != 0) throw new InvalidOperationException(); - int v; + long v; ReadVarIntTo(out v); return v; } @@ -145,7 +151,7 @@ private void WriteVarint(long value) { while ((value & ~0x7fL) != 0) { stream.WriteByte((Byte)(0x80 | value)); - value >>= 7; + value = (long)((ulong)value >> 7); } stream.WriteByte((Byte)value); }