Module: Bones::RPC::Protocol::BinaryHelper

Included in:
ExtMessage
Defined in:
lib/bones/rpc/protocol/binary_helper.rb

Overview

The base class for building all messages needed to implement the Bones RPC Protocol. It provides a minimal DSL for defining typed fields for serialization and deserialization over the wire.

Examples:


class KillCursors < Bones::RPC::Protocol::Message
  # header fields
  int32 :length
  int32 :request_id
  int32 :response_to
  int32 :op_code

  # message fields
  int32 :reserved
  int32 :number_of_cursors
  int64 :cursor_ids, type: :array

  # Customize field reader
  def number_of_cursors
    cursor_ids.length
  end
end

Defined Under Namespace

Modules: ClassMethods

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



74
75
76
77
# File 'lib/bones/rpc/protocol/binary_helper.rb', line 74

def included(base)
  super
  base.extend(ClassMethods)
end

Instance Method Details

#inspectString

Returns the nicely formatted version of the message.

Returns:

  • (String)

    the nicely formatted version of the message



62
63
64
65
66
67
68
# File 'lib/bones/rpc/protocol/binary_helper.rb', line 62

def 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:

Returns:

  • (nil)

    nil.

Since:

  • 1.0.0



43
# File 'lib/bones/rpc/protocol/binary_helper.rb', line 43

def receive_replies(connection); end

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

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

Examples:

Serliaze the message.

message.serialize

Parameters:

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

    A buffer to serialize to.

Returns:

  • (String)

    The result of serliazing this message

Raises:

  • (NotImplementedError)

Since:

  • 1.0.0



56
57
58
# File 'lib/bones/rpc/protocol/binary_helper.rb', line 56

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