Module: MarilynRPC::MailFactory

Includes:
MailHelper
Defined in:
lib/marilyn-rpc/mails.rb

Overview

Helper to destiguish between the different mails

Constant Summary collapse

TYPE_LOOK_UP =

table which contains all types that can be unpacked

{
  MarilynRPC::CallRequestMail::TYPE   => MarilynRPC::CallRequestMail,
  MarilynRPC::CallResponseMail::TYPE  => MarilynRPC::CallResponseMail,
  MarilynRPC::ExceptionMail::TYPE     => MarilynRPC::ExceptionMail
}

Constants included from MailHelper

MarilynRPC::MailHelper::SERIALIZER

Class Method Summary collapse

Class Method Details

.build_call(tag, path, method, args) ⇒ Object

builds the binary data for a method call, it inlines some of the packing for performance critical applications.

Parameters:

  • tag (Object)

    the tag for the object is relevate for multuplexing, it should be unique on a per conncetion base

  • path (Object)

    the path to identifiy the service

  • method (Symbol, String)

    the method name to call on the service

  • args (Array<Object>)

    the arguments that are passed to the remote side

Returns:

  • (Object)

    the result of the call



79
80
81
82
83
84
# File 'lib/marilyn-rpc/mails.rb', line 79

def self.build_call(tag, path, method, args)
  data = MarilynRPC::MailHelper::SERIALIZER.dump([tag, path, method, args])
  [
    data.size, MarilynRPC::CallRequestMail::TYPE
  ].pack(MarilynRPC::Envelope::HEADER_ENCODING) + data
end

.unpack(envelope) ⇒ MarilynRPC::CallRequestMail, ...

Parses the envelop and generate the correct mail.

Parameters:

Returns:



61
62
63
64
65
66
67
68
# File 'lib/marilyn-rpc/mails.rb', line 61

def self.unpack(envelope)      
  if mail_klass = TYPE_LOOK_UP[envelope.type]
    mail = mail_klass.new(*SERIALIZER.load(envelope.content))
  else
    raise MarilynRPC::BrokenEnvelopeError.new \
      "The passed envelope is broken, no (correct) type!"
  end
end