Class: Stargate::Marshal::Marshaller

Inherits:
Object
  • Object
show all
Defined in:
lib/stargate/marshal/marshaller.rb

Overview

Internal: Use it in order to pack data for exchange. Marshaller is created per instance of registry version. It packs basic values and objects of registered classes into Stargate::Marshal::Payload wraps.

Instance Method Summary collapse

Constructor Details

#initialize(registry_version) ⇒ Marshaller

Public: Constructor. Initializes marshaller for given registry version object.


7
8
9
# File 'lib/stargate/marshal/marshaller.rb', line 7

def initialize(registry_version)
  @registry_version = registry_version
end

Instance Method Details

#marshal(obj) ⇒ Object

Public: Returns given object after marshalling.


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/stargate/marshal/marshaller.rb', line 12

def marshal(obj)
  case obj
  when String, Numeric, TrueClass, FalseClass, Float, BigDecimal, NilClass
    Payload.new(Payload::SIMPLE, obj)
  when Symbol
    Payload.new(Payload::SYMBOL, obj.to_s)
  when Hash
    Payload.new(Payload::HASH, marshal_hash(obj))
  when Array
    Payload.new(Payload::LIST, marshal_list(obj))
  else
    Payload.new(*marshal_complex_object(obj))
  end
end