From b3d86a537e8f363fa0a82fa8faff3d9f57083ab3 Mon Sep 17 00:00:00 2001 From: Theo Date: Sat, 21 Sep 2013 19:47:45 +0200 Subject: [PATCH] Encode UUIDs as 128 bit numbers not VARINTs This fixes #43 --- lib/cql/protocol/encoding.rb | 6 +++++- spec/cql/protocol/encoding_spec.rb | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/cql/protocol/encoding.rb b/lib/cql/protocol/encoding.rb index b5dd4c1..40d81ce 100644 --- a/lib/cql/protocol/encoding.rb +++ b/lib/cql/protocol/encoding.rb @@ -27,7 +27,11 @@ def write_long_string(buffer, str) end def write_uuid(buffer, uuid) - write_varint(buffer, uuid.value) + v = uuid.value + write_int(buffer, (v >> 96) & 0xffffffff) + write_int(buffer, (v >> 64) & 0xffffffff) + write_int(buffer, (v >> 32) & 0xffffffff) + write_int(buffer, v & 0xffffffff) end def write_string_list(buffer, strs) diff --git a/spec/cql/protocol/encoding_spec.rb b/spec/cql/protocol/encoding_spec.rb index 6b73196..ac6a7ca 100644 --- a/spec/cql/protocol/encoding_spec.rb +++ b/spec/cql/protocol/encoding_spec.rb @@ -121,6 +121,11 @@ module Protocol buffer.should eql_bytes("\xA4\xA7\t\x00$\xE1\x11\xDF\x89$\x00\x1F\xF3Y\x17\x11") end + it 'encodes a UUID as 16 bytes' do + Encoding.write_uuid(buffer, Uuid.new('00000000-24e1-11df-8924-001ff3591711')) + buffer.size.should eql(16) + end + it 'appends to the buffer' do buffer << 'FOO' Encoding.write_uuid(buffer, uuid)