Module: Bones::RPC::Adapter::MessagePack
- Defined in:
- lib/bones/rpc/adapter/msgpack.rb
Instance Method Summary collapse
- #pack(message, buffer = "") ⇒ Object
- #parser(data) ⇒ Object
- #read(unpacker) ⇒ Object
- #unpack(buffer) ⇒ Object
- #unpack_stream(stream) ⇒ Object
- #unpacker(data) ⇒ Object
- #unpacker_pos(parser) ⇒ Object
- #unpacker_seek(parser, n) ⇒ Object
Instance Method Details
#pack(message, buffer = "") ⇒ Object
11 12 13 |
# File 'lib/bones/rpc/adapter/msgpack.rb', line 11 def pack(, buffer="") buffer << ::MessagePack.pack() end |
#parser(data) ⇒ Object
32 33 34 |
# File 'lib/bones/rpc/adapter/msgpack.rb', line 32 def parser(data) Adapter::Parser.new(self, data) end |
#read(unpacker) ⇒ Object
24 25 26 |
# File 'lib/bones/rpc/adapter/msgpack.rb', line 24 def read(unpacker) (unpacker.adapter_unpacker ||= ::MessagePack::Unpacker.new(unpacker.buffer)).read end |
#unpack(buffer) ⇒ Object
15 16 17 |
# File 'lib/bones/rpc/adapter/msgpack.rb', line 15 def unpack(buffer) ::MessagePack.unpack(buffer) end |
#unpack_stream(stream) ⇒ Object
19 20 21 22 |
# File 'lib/bones/rpc/adapter/msgpack.rb', line 19 def unpack_stream(stream) buffer = StringIO.new(stream) ::MessagePack::Unpacker.new(buffer).read end |
#unpacker(data) ⇒ Object
28 29 30 |
# File 'lib/bones/rpc/adapter/msgpack.rb', line 28 def unpacker(data) ::MessagePack::Unpacker.new(StringIO.new(data)) end |
#unpacker_pos(parser) ⇒ Object
36 37 38 39 40 |
# File 'lib/bones/rpc/adapter/msgpack.rb', line 36 def unpacker_pos(parser) size = parser.unpacker.buffer.size pos = parser.unpacker.buffer.io.pos (pos > size) ? (pos - size) : 0 end |
#unpacker_seek(parser, n) ⇒ Object
42 43 44 45 46 |
# File 'lib/bones/rpc/adapter/msgpack.rb', line 42 def unpacker_seek(parser, n) pos = unpacker_pos(parser) parser.unpacker.buffer.skip(n - pos) if pos < n return pos end |