Class: Hypertube::Core::Protocol::CommandSerializer
- Inherits:
-
Object
- Object
- Hypertube::Core::Protocol::CommandSerializer
- Defined in:
- lib/hypertube-ruby-sdk/core/protocol/command_serializer.rb
Class Method Summary collapse
- .serialize(root_command, connection_data = nil, runtime_version = 0) ⇒ Object
- .serialize_recursively(command, buffer) ⇒ Object
Class Method Details
.serialize(root_command, connection_data = nil, runtime_version = 0) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hypertube-ruby-sdk/core/protocol/command_serializer.rb', line 13 def self.serialize(root_command, connection_data = nil, runtime_version = 0) buffer = ''.dup buffer << [root_command.runtime_name, runtime_version].pack('C*') buffer << if connection_data connection_data.serialize_connection_data.pack('C*') else [0, 0, 0, 0, 0, 0, 0].pack('C*') end buffer << [Hypertube::Utils::RuntimeNameHt::RUBY, root_command.command_type].pack('C*') # Payload (recursive) serialize_recursively(root_command, buffer) buffer.bytes end |
.serialize_recursively(command, buffer) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hypertube-ruby-sdk/core/protocol/command_serializer.rb', line 32 def self.serialize_recursively(command, buffer) command.payload.each do |item| if item.is_a?(Hypertube::Utils::Command) buffer << Hypertube::Core::Protocol::TypeSerializer.serialize_command(item).pack('C*') serialize_recursively(item, buffer) elsif Hypertube::Utils::TypesHandler.primitive_or_none?(item) buffer << Hypertube::Core::Protocol::TypeSerializer.serialize_primitive(item).pack('C*') else cached_reference = Hypertube::Core::ReferenceCache::ReferencesCache.instance.cache_reference(item) ref_command = Hypertube::Utils::Command.new(Hypertube::Utils::RuntimeNameHt::RUBY, Hypertube::Utils::CommandType::REFERENCE, [cached_reference]) buffer << Hypertube::Core::Protocol::TypeSerializer.serialize_command(ref_command).pack('C*') serialize_recursively(ref_command, buffer) end end end |