Class: RightScale::CommandSerializer
- Defined in:
- lib/right_agent/command/command_serializer.rb
Constant Summary collapse
- SEPARATOR =
String appended to serialized data to delimit between commands
"\n#GO\n"
Class Method Summary collapse
-
.dump(command) ⇒ Object
Serialize given command so it can be sent to command listener.
-
.load(data) ⇒ Object
Deserialize command that was previously serialized with
dump
.
Class Method Details
.dump(command) ⇒ Object
Serialize given command so it can be sent to command listener
Parameters
- command(Object)
-
Command to serialize
Return
- data(String)
-
Corresponding serialized data
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/right_agent/command/command_serializer.rb', line 39 def self.dump(command) # Set the encoding before serialization otherwise YAML will serialize # UTF8 characters as binary data. This can cause some quirks we'd rather # avoid, such as the deserialized binary data having no encoding on # deserialization set_encoding(command) data = YAML::dump(command) data += SEPARATOR end |
.load(data) ⇒ Object
Deserialize command that was previously serialized with dump
Parameters
- data(String)
-
String containing serialized data
Return
- command(Object)
-
Deserialized command
Raise
(RightScale::Exceptions::IO): If serialized data is incorrect
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/right_agent/command/command_serializer.rb', line 60 def self.load(data) # Data coming from eventmachine is cleaned of it's encoding, so set it # to UTF-8 manually before deserializing or you'll throw transcode errors. set_encoding(data) command = YAML::load(data) raise RightScale::Exceptions::IO, "Invalid serialized command:\n#{data}" unless command command rescue RightScale::Exceptions::IO raise rescue Exception => e raise RightScale::Exceptions::IO, "Invalid serialized command: #{e.message}\n#{data}" end |