Sha256: d033aa0097011a5ea63a8be68e97e87d243ce0ffefe87025b760a4407a721b67

Contents?: true

Size: 995 Bytes

Versions: 1

Compression:

Stored size: 995 Bytes

Contents

require 'msgpack'

module RabbitRPC
  class Message

    attr_reader :method_name, :args

    def initialize(method_name, *args)
      @method_name = method_name
      @args        = args
    end

    # Squeezes and serializes the RPC method name and arguments
    #
    # Returns the packed and serialized string
    def pack
      serialize(method: @method_name, args: @args)
    end

    # Unpacks a serialized message to a hash containing the method and
    # its args. This method needs to be modified if a serializer other
    # than MessagePack is to be used.
    #
    # Returns a Hash
    def self.unpack(message)
      MessagePack.unpack message
    end

    def self.generate_id
      SecureRandom.uuid
    end

    private

    # Private: Serialize the message. Currently using message pack. The
    # implementation can be changed in order to use some other serializer.
    #
    # Returns the serialized String
    def serialize(message)
      message.to_msgpack
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rabbit_rpc-0.0.2 lib/rabbit_rpc/message.rb