Class: PipelineToolkit::MessageCoder
- Inherits:
-
Object
- Object
- PipelineToolkit::MessageCoder
- Defined in:
- lib/pipeline_toolkit/message_coder.rb
Overview
Encode and decode messages using Marshal
Class Method Summary collapse
-
.decode(str) ⇒ Object
Decode the binary string into a hash.
-
.encode(message) ⇒ Object
Encode the hash message.
Class Method Details
.decode(str) ⇒ Object
Decode the binary string into a hash
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/pipeline_toolkit/message_coder.rb', line 27 def self.decode(str) str.chomp! obj = MessagePack.unpack(Base64.decode64(str)) obj = case obj when Hash # makes code a little more readable IndifferentHash.new(obj) else obj end end |
.encode(message) ⇒ Object
Encode the hash message
15 16 17 18 19 20 |
# File 'lib/pipeline_toolkit/message_coder.rb', line 15 def self.encode() # NB: Using Msgpack because it's 9-10x faster than altnatives # See http://gist.github.com/190849 # Using Base64 because ASCII is friendly to pipes. Base64.encode64(MessagePack.pack()).delete("\r\n") end |