Class: Arpie::SizedProtocol

Inherits:
Protocol show all
Defined in:
lib/arpie/protocol.rb

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

MTU

Instance Attribute Summary

Attributes inherited from Protocol

#metabuffer, #stowbuffer

Instance Method Summary collapse

Methods inherited from Protocol

#again!, #assemble, #assemble!

Methods included from Arpie

#bogon!, #incomplete!

Instance Method Details

#from(binary) {|| ... } ⇒ Object

Yields:

  • ()


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

Yields:

  • ([object.size, object].pack('Qa*'))


282
283
284
# File 'lib/arpie/protocol.rb', line 282

def to object
  yield [object.size, object].pack('Qa*')
end