module Bones::RPC::Protocol::BinaryHelper
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.
@example
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
Private Class Methods
Extends the including class with ClassMethods
.
@param [Class] subclass the inheriting class
# File lib/bones/rpc/protocol/binary_helper.rb, line 74 def included(base) super base.extend(ClassMethods) end
Public Instance Methods
@return [String] the nicely formatted version of the message
# 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
Default implementation for a message is to do nothing when receiving replies.
@example Receive replies.
message.receive_replies(connection)
@param [ Connection
] connection The connection.
@return [ nil ] nil.
@since 0.0.1
# File lib/bones/rpc/protocol/binary_helper.rb, line 43 def receive_replies(connection); end
Serializes the message and all of its fields to a new buffer or to the provided buffer.
@example Serliaze the message.
message.serialize
@param [ String ] buffer A buffer to serialize to.
@return [ String ] The result of serliazing this message
@since 0.0.1
# 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