Mercurial > hg > ucis.core
diff ProtocolBuffers.cs @ 17:5d9a7186c9f7
ProtocolBuffers: fix handling of 64 bit varint
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Wed, 10 Apr 2013 01:33:32 +0200 |
parents | 2e0ff842aa4a |
children |
line wrap: on
line diff
--- 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); }