Class: Arpie::SizedProtocol
Overview
A sample binary protocol, which simply prefixes each message with the size of the data to be expected.
Constant Summary collapse
- CAN_SEPARATE_MESSAGES =
true
Constants included from Arpie
Instance Method Summary collapse
Methods inherited from Protocol
Methods included from Arpie
Instance Method Details
#from(binary) {|| ... } ⇒ Object
262 263 264 265 266 267 |
# File 'lib/arpie/protocol.rb', line 262 def from binary sz = binary.unpack('Q')[0] or incomplete! binary.size >= sz + 8 or incomplete! yield binary[8, sz] 8 + sz end |
#to(object) {|[object.size, object].pack('Qa*')| ... } ⇒ Object
269 270 271 |
# File 'lib/arpie/protocol.rb', line 269 def to object yield [object.size, object].pack('Qa*') end |