Module: Binary::Protocol

Defined in:
lib/binary/protocol.rb,
lib/binary/protocol/version.rb,
lib/binary/protocol/extensions/module.rb

Defined Under Namespace

Modules: ClassMethods, Extensions

Constant Summary collapse

BYTES_8 =
1.freeze
BYTES_16 =
2.freeze
BYTES_32 =
4.freeze
BYTES_64 =
8.freeze
INT8_PACK =

8-bit signed (signed char)

'c'.freeze
INT16_PACK =

16-bit signed, native endian (int16_t)

's'.freeze
INT32_PACK =

32-bit signed, native endian (int32_t)

'l'.freeze
INT64_PACK =

64-bit signed, native endian (int64_t)

'q'.freeze
INT16BE_PACK =

16-bit signed, big-endian

's>'.freeze
INT32BE_PACK =

32-bit signed, big-endian

'l>'.freeze
INT64BE_PACK =

64-bit signed, big-endian

'q>'.freeze
INT16LE_PACK =

16-bit signed, little-endian

's<'.freeze
INT32LE_PACK =

32-bit signed, little-endian

'l<'.freeze
INT64LE_PACK =

64-bit signed, little-endian

'q<'.freeze
UINT8_PACK =

8-bit unsigned (unsigned char)

'C'.freeze
UINT16_PACK =

16-bit unsigned, native endian (uint16_t)

'S'.freeze
UINT32_PACK =

32-bit unsigned, native endian (uint32_t)

'L'.freeze
UINT64_PACK =

64-bit unsigned, native endian (uint64_t)

'Q'.freeze
UINT16BE_PACK =

16-bit unsigned, network (big-endian) byte order

'n'.freeze
UINT32BE_PACK =

32-bit unsigned, network (big-endian) byte order

'N'.freeze
UINT64BE_PACK =

64-bit unsigned, network (big-endian) byte order

'Q>'.freeze
UINT16LE_PACK =

16-bit unsigned, VAX (little-endian) byte order

'v'.freeze
UINT32LE_PACK =

32-bit unsigned, VAX (little-endian) byte order

'V'.freeze
UINT64LE_PACK =

64-bit unsigned, VAX (little-endian) byte order

'Q<'.freeze
SINGLE_PACK =

32-bit single-precision, native format

'F'.freeze
DOUBLE_PACK =

64-bit double-precision, native format

'D'.freeze
SINGLEBE_PACK =

32-bit sinlge-precision, network (big-endian) byte order

'g'.freeze
DOUBLEBE_PACK =

64-bit double-precision, network (big-endian) byte order

'G'.freeze
SINGLELE_PACK =

32-bit sinlge-precision, little-endian byte order

'e'.freeze
DOUBLELE_PACK =

64-bit double-precision, little-endian byte order

'E'.freeze
VERSION =
"0.0.1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Extends the including class with ClassMethods.

Parameters:

  • subclass (Class)

    the inheriting class



46
47
48
49
50
# File 'lib/binary/protocol.rb', line 46

def included(base)
  super

  base.extend ClassMethods
end

Instance Method Details

#deserialize(buffer) ⇒ Object



362
363
364
365
366
367
# File 'lib/binary/protocol.rb', line 362

def deserialize(buffer)
  self.class.fields.each do |field|
    __send__(:"deserialize_#{field}", buffer)
  end
  self
end

#inspectString

Returns the nicely formatted version of the message.

Returns:

  • (String)

    the nicely formatted version of the message



380
381
382
383
384
385
386
# File 'lib/binary/protocol.rb', line 380

def inspect
  fields = self.class.fields.map do |field|
    "@#{field}=" + __send__(field).inspect
  end
  "#<#{self.class.name} " <<
  "#{fields * " "}>"
end

#pretty_inspectObject



388
389
390
391
392
393
394
# File 'lib/binary/protocol.rb', line 388

def pretty_inspect
  fields = self.class.fields.map do |field|
    "@#{field}=" + __send__(field).inspect
  end
  "#<#{self.class.name}\n" <<
  "  #{fields * "\n  "}>"
end

#receive_replies(connection) ⇒ nil

Default implementation for a message is to do nothing when receiving replies.

Examples:

Receive replies.

message.receive_replies(connection)

Parameters:

  • connection (Connection)

    The connection.

Returns:

  • (nil)

    nil.

Since:

  • 1.0.0



360
# File 'lib/binary/protocol.rb', line 360

def receive_replies(connection); end

#serialize(buffer = "") ⇒ String Also known as: to_s

Serializes the message and all of its fields to a new buffer or to the provided buffer.

Parameters:

  • buffer (String) (defaults to: "")

    a buffer to serialize to

Returns:

  • (String)

    the result of serliazing this message

Raises:

  • (NotImplementedError)


374
375
376
# File 'lib/binary/protocol.rb', line 374

def serialize(buffer = "")
  raise NotImplementedError, "This method is generated after calling #finalize on a message class"
end