class Bones::RPC::Adapter::Msgpack::Ruby::Decoder

Constants

DECODINGS
DOUBLE_FMT
FLOAT_FMT

Attributes

buffer[R]

Public Class Methods

new(buffer) click to toggle source
# File lib/bones/rpc/adapter/msgpack/ruby.rb, line 15
def initialize(buffer)
  @buffer = ::Bones::RPC::Parser::Buffer.new(buffer)
end

Public Instance Methods

consume_array(size) click to toggle source
# File lib/bones/rpc/adapter/msgpack/ruby.rb, line 100
def consume_array(size)
  Array.new(size) { consume_next }
end
consume_byte() click to toggle source
# File lib/bones/rpc/adapter/msgpack/ruby.rb, line 60
def consume_byte
  buffer.getbyte
end
consume_double() click to toggle source
# File lib/bones/rpc/adapter/msgpack/ruby.rb, line 89
def consume_double
  d, = buffer.read(8).unpack(DOUBLE_FMT)
  d
end
consume_float() click to toggle source
# File lib/bones/rpc/adapter/msgpack/ruby.rb, line 84
def consume_float
  f, = buffer.read(4).unpack(FLOAT_FMT)
  f
end
consume_int16() click to toggle source
# File lib/bones/rpc/adapter/msgpack/ruby.rb, line 64
def consume_int16
  (consume_byte << 8) | consume_byte
end
consume_int32() click to toggle source
# File lib/bones/rpc/adapter/msgpack/ruby.rb, line 68
def consume_int32
  (consume_byte << 24) | (consume_byte << 16) | (consume_byte << 8) | consume_byte
end
consume_int64() click to toggle source
# File lib/bones/rpc/adapter/msgpack/ruby.rb, line 72
def consume_int64
  n  = (consume_byte << 56)
  n |= (consume_byte << 48)
  n |= (consume_byte << 40)
  n |= (consume_byte << 32)
  n |= (consume_byte << 24)
  n |= (consume_byte << 16)
  n |= (consume_byte << 8)
  n |=  consume_byte
  n
end
consume_next() click to toggle source
# File lib/bones/rpc/adapter/msgpack/ruby.rb, line 104
def consume_next
  b = consume_byte
  if (method = DECODINGS[b])
    method.call(self)
  elsif b <= 0b01111111
    b
  elsif b & 0b11100000 == 0b11100000
    b - 0x100
  elsif b & 0b11100000 == 0b10100000
    size = b & 0b00011111
    consume_string(size)
  elsif b & 0b11110000 == 0b10010000
    size = b & 0b00001111
    consume_array(size)
  elsif b & 0b11110000 == 0b10000000
    size = b & 0b00001111
    Hash[*consume_array(size * 2)]
  end
end
consume_string(size, encoding=Encoding::UTF_8) click to toggle source
# File lib/bones/rpc/adapter/msgpack/ruby.rb, line 94
def consume_string(size, encoding=Encoding::UTF_8)
  s = buffer.read(size)
  s.force_encoding(encoding)
  s
end
next() click to toggle source
# File lib/bones/rpc/adapter/msgpack/ruby.rb, line 19
def next
  buffer.transaction do
    consume_next
  end
rescue TypeError
  raise EOFError
end
Also aliased as: read
read()
Alias for: next