Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Commit

Permalink
Encode UUIDs as 128 bit numbers not VARINTs
Browse files Browse the repository at this point in the history
This fixes #43
  • Loading branch information
iconara committed Sep 21, 2013
1 parent b40533b commit b3d86a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/cql/protocol/encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions spec/cql/protocol/encoding_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b3d86a5

Please sign in to comment.