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, VERSION

Instance Method Summary collapse

Methods inherited from Protocol

#assemble, #assemble!

Methods included from Arpie

#bogon!, #incomplete!

Instance Method Details

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

Yields:

  • ()


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

Yields:

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


269
270
271
# File 'lib/arpie/protocol.rb', line 269

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