Module: Riakpb::Util::Encode

Included in:
Client::Rpc
Defined in:
lib/riakpb/util/encode.rb

Instance Method Summary collapse

Instance Method Details

#assemble_request(mc, msg = '') ⇒ String

Construct a Request Message for Riakpb, which adheres to the following structure:

00 00 00 07 09 0A 01 62 12 01 6B
|----Len---|MC|----Message-----|

Returns:

  • (String)

    the assigned hostname

Raises:

  • (TypeError)

    if an invalid hostname is given



15
16
17
18
19
20
# File 'lib/riakpb/util/encode.rb', line 15

def assemble_request(mc, msg='')
  raise TypeError, t("message_code_invalid")  unless mc.is_a?(Fixnum)
  raise TypeError, t("pb_message_invalid")    unless msg.is_a?(String)
  
  encode_message mc, msg
end

#encode_message(mc, msg = '') ⇒ Object



22
23
24
25
26
# File 'lib/riakpb/util/encode.rb', line 22

def encode_message(mc, msg='')
  message = [mc].pack('c') + msg
  
  message = [message.size].pack('N') + message
end