class Invoke
Represents a method invocation.
Definitions
def initialize(id, name, arguments, options, block_given)
Initialize a new invocation message.
Signature
-
parameter
idInteger The transaction ID.
-
parameter
nameSymbol The method name to invoke.
-
parameter
argumentsArray The positional arguments.
-
parameter
optionsHash The keyword arguments.
-
parameter
block_givenBoolean Whether a block was provided.
Implementation
def initialize(id, name, arguments, options, block_given)
@id = id
@name = name
@arguments = arguments
@options = options
@block_given = block_given
end
attr :id
Signature
-
attribute
Integer The transaction ID.
attr :name
Signature
-
attribute
Symbol The method name.
attr :arguments
Signature
-
attribute
Array The positional arguments.
attr :options
Signature
-
attribute
Hash The keyword arguments.
attr :block_given
Signature
-
attribute
Boolean Whether a block was provided.
def pack(packer)
Pack the invocation into a MessagePack packer.
Signature
-
parameter
packerMessagePack::Packer The packer to write to.
Implementation
def pack(packer)
packer.write(@id)
packer.write(@name)
packer.write(@arguments.size)
@arguments.each do |argument|
packer.write(argument)
end
packer.write(@options.size)
@options.each do |key, value|
packer.write(key)
packer.write(value)
end
packer.write(@block_given)
end
def self.unpack(unpacker)
Unpack an invocation from a MessagePack unpacker.
Signature
-
parameter
unpackerMessagePack::Unpacker The unpacker to read from.
-
returns
Invoke A new invocation instance.
Implementation
def self.unpack(unpacker)
id = unpacker.read
name = unpacker.read
arguments = Array.new(unpacker.read){unpacker.read}
options = Array.new(unpacker.read){[unpacker.read, unpacker.read]}.to_h
block_given = unpacker.read
return self.new(id, name, arguments, options, block_given)
end