Skip to content
This repository has been archived by the owner on Jul 7, 2019. It is now read-only.

Commit

Permalink
Large counters (> 2^32) are deserialized properly. Fixes issue #77
Browse files Browse the repository at this point in the history
  • Loading branch information
enyim committed Oct 3, 2011
1 parent 81d7c67 commit 67678bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Enyim.Caching/Memcached/Protocol/Binary/BinaryConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public static unsafe ulong DecodeUInt64(byte* buffer, int offset)
{
buffer += offset;

int part1 = (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
int part2 = (buffer[4] << 24) | (buffer[5] << 16) | (buffer[6] << 8) | buffer[7];
var part1 = (uint)((buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3]);
var part2 = (uint)((buffer[4] << 24) | (buffer[5] << 16) | (buffer[6] << 8) | buffer[7]);

return (ulong)(((long)part2) | (part1 << 32));
return ((ulong)part1 << 32) | part2;
}

public static unsafe void EncodeUInt16(uint value, byte[] buffer, int offset)
Expand Down
12 changes: 12 additions & 0 deletions MemcachedTest/MemcachedClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,18 @@ public void FlushTest()
Assert.IsNull(client.Get("gfsd"), "FlushAll() failed.");
}
}

[TestCase]
public void IncrementLongTest()
{
var initialValue = 56UL * (ulong)System.Math.Pow(10, 11) + 1234;

using (MemcachedClient client = GetClient())
{
Assert.AreEqual(initialValue, client.Increment("VALUE", initialValue, 2UL), "Non-existing value should be set to default");
Assert.AreEqual(initialValue + 24, client.Increment("VALUE", 10UL, 24UL));
}
}
}
}

Expand Down

0 comments on commit 67678bf

Please sign in to comment.