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 Attribute Summary
Attributes inherited from Protocol
Instance Method Summary collapse
Methods inherited from Protocol
#again!, #assemble, #assemble!
Methods included from Arpie
Instance Method Details
#from(binary) {|| ... } ⇒ Object
275 276 277 278 279 280 |
# File 'lib/arpie/protocol.rb', line 275 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
282 283 284 |
# File 'lib/arpie/protocol.rb', line 282 def to object yield [object.size, object].pack('Qa*') end |