lib/gibson/gibson.rb in gibson-1.0.1 vs lib/gibson/gibson.rb in gibson-1.0.2
- old
+ new
@@ -44,11 +44,11 @@
if encoding == Protocol::ENCODINGS[:plain]
data.unpack( 'Z' + size.to_s )[0]
# number
elsif encoding == Protocol::ENCODINGS[:number]
# 32 bit integer ?
- if size == 4:
+ if size == 4
data.unpack( 'l<' )[0]
else
data.unpack( 'q<' )[0]
end
else
@@ -59,11 +59,11 @@
def decode_kval( data, size )
left = size - 4
count, data = data.unpack( 'L<a' + left.to_s )
obj = {}
- count.times { |i|
+ count.times do |i|
left -= 4
klen, data = data.unpack( 'L<a' + left.to_s )
left -= klen
key, data = data.unpack( 'a' + klen.to_s + 'a' + left.to_s )
@@ -76,21 +76,24 @@
left -= vsize
value, data = data.unpack( 'a' + vsize.to_s + 'a' + left.to_s )
obj[key] = decode Protocol::REPLIES[:val], enc, vsize, value
- }
+ end
obj
end
def decode( code, encoding, size, data )
if code == Protocol::REPLIES[:val]
decode_val encoding, size, data
+
elsif code == Protocol::REPLIES[:kval]
decode_kval data, size
+
elsif code == Protocol::REPLIES[:ok]
true
+
elsif Protocol.error? code
raise Protocol::ERRORS[code]
else
data