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

Fixing bug with appending varint of 0. #112

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/cql/protocol/cql_byte_buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ def append_long(n)
def append_varint(n)
num = n
bytes = []

bytes << 0 if num == 0

until num == 0
bytes << (num & 0xff)
num = num >> 8
Expand Down Expand Up @@ -282,4 +285,4 @@ def append_float(n)
DECIMAL_POINT = '.'.freeze
end
end
end
end
7 changes: 6 additions & 1 deletion spec/cql/protocol/cql_byte_buffer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,11 @@ module Protocol
end

describe '#append_varint' do
it 'encodes zero' do
buffer.append_varint(0)
buffer.should eql_bytes("\x00")
end

it 'encodes a variable length integer' do
buffer.append_varint(1231312312331283012830129382342342412123)
buffer.should eql_bytes("\x03\x9EV \x15\f\x03\x9DK\x18\xCDI\\$?\a[")
Expand Down Expand Up @@ -892,4 +897,4 @@ module Protocol
end
end
end
end
end