Module: EMRPC::MarshalProtocol
- Defined in:
- lib/emrpc/protocols/marshal_protocol.rb
Constant Summary collapse
- DEFAULT_CONST =
Marshal
Class Method Summary collapse
-
.included(base) ⇒ Object
By default, include Marshal-based serialization module.
-
.new(marshal_const) ⇒ Object
Creates new protocol using specified dump/load interface.
Class Method Details
.included(base) ⇒ Object
By default, include Marshal-based serialization module.
28 29 30 31 |
# File 'lib/emrpc/protocols/marshal_protocol.rb', line 28 def self.included(base) base.send(:include, new(DEFAULT_CONST)) #STDERR.puts "# Info: #{self} included into #{base} directly: using #{self}.new(#{DEFAULT_CONST})." end |
.new(marshal_const) ⇒ Object
Creates new protocol using specified dump/load interface. Note: interface must be a constant! See examples below. Examples:
1. include MarshalProtocol.new(Marshal)
2. include MarshalProtocol.new(YAML)
3. include MarshalProtocol.new(JSON)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/emrpc/protocols/marshal_protocol.rb', line 9 def self.new(marshal_const) const_name = marshal_const.name mod = Module.new mod.class_eval " def send_marshalled_message(msg)\n send_message(\#{const_name}.dump(msg))\n end\n def receive_message(msg)\n receive_marshalled_message(\#{const_name}.load(msg))\n rescue Exception => e\n rescue_marshal_error(e)\n end\n EOF\n mod\nend\n", __FILE__, __LINE__ |