class Bones::RPC::Adapter::JSON::Unpacker

I apologize for how nasty this unpacker is; Oj or Yajl would be better fits

Constants

ARRAY_START

Attributes

buffer[R]

Public Class Methods

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

Public Instance Methods

read() click to toggle source
# File lib/bones/rpc/adapter/json.rb, line 46
def read
  if skip_to_array_start
    unpack_stream("", buffer.pos)
  else
    nil
  end
end

Private Instance Methods

skip_to_array_start() click to toggle source
# File lib/bones/rpc/adapter/json.rb, line 71
def skip_to_array_start
  i = buffer.pos
  case buffer.getc
  when ARRAY_START
    buffer.seek(i)
    return true
  when nil
    return false
  else
    skip_to_array_start
  end
end
unpack_stream(temp, pos) click to toggle source
# File lib/bones/rpc/adapter/json.rb, line 56
def unpack_stream(temp, pos)
  if char = buffer.getc
    temp << char
    term = begin
      ::JSON.load(temp)
    rescue ::JSON::ParserError
      unpack_stream(temp, pos)
    end
    return term
  else
    buffer.seek(pos)
    return nil
  end
end