Class: Bones::RPC::Adapter::Msgpack::Ruby::Decoder
- Inherits:
-
Object
- Object
- Bones::RPC::Adapter::Msgpack::Ruby::Decoder
- Defined in:
- lib/bones/rpc/adapter/msgpack/ruby.rb
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
Instance Method Summary collapse
- #consume_array(size) ⇒ Object
- #consume_byte ⇒ Object
- #consume_double ⇒ Object
- #consume_float ⇒ Object
- #consume_int16 ⇒ Object
- #consume_int32 ⇒ Object
- #consume_int64 ⇒ Object
- #consume_next ⇒ Object
- #consume_string(size, encoding = Encoding::UTF_8) ⇒ Object
-
#initialize(buffer) ⇒ Decoder
constructor
A new instance of Decoder.
- #next ⇒ Object (also: #read)
Constructor Details
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
13 14 15 |
# File 'lib/bones/rpc/adapter/msgpack/ruby.rb', line 13 def buffer @buffer end |
Instance Method Details
#consume_array(size) ⇒ Object
100 101 102 |
# File 'lib/bones/rpc/adapter/msgpack/ruby.rb', line 100 def consume_array(size) Array.new(size) { consume_next } end |
#consume_byte ⇒ Object
60 61 62 |
# File 'lib/bones/rpc/adapter/msgpack/ruby.rb', line 60 def consume_byte buffer.getbyte end |
#consume_double ⇒ Object
89 90 91 92 |
# File 'lib/bones/rpc/adapter/msgpack/ruby.rb', line 89 def consume_double d, = buffer.read(8).unpack(DOUBLE_FMT) d end |
#consume_float ⇒ Object
84 85 86 87 |
# File 'lib/bones/rpc/adapter/msgpack/ruby.rb', line 84 def consume_float f, = buffer.read(4).unpack(FLOAT_FMT) f end |
#consume_int16 ⇒ Object
64 65 66 |
# File 'lib/bones/rpc/adapter/msgpack/ruby.rb', line 64 def consume_int16 (consume_byte << 8) | consume_byte end |
#consume_int32 ⇒ Object
68 69 70 |
# 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 ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# 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 ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# 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) ⇒ Object
94 95 96 97 98 |
# 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 ⇒ Object Also known as: read
19 20 21 22 23 24 25 |
# File 'lib/bones/rpc/adapter/msgpack/ruby.rb', line 19 def next buffer.transaction do consume_next end rescue TypeError raise EOFError end |