Class: Stargate::Marshal::Unmarshaller
- Inherits:
-
Object
- Object
- Stargate::Marshal::Unmarshaller
- Defined in:
- lib/stargate/marshal/unmarshaller.rb
Overview
Internal: On the client side there’s unmarshalling needed then. Use this unmarshaller to unpack data. Unmarshaller is assigned to a module (namespace). It shall look up within that module in case of unpacking complex objects of specific type.
Instance Method Summary collapse
-
#unmarshal(data) ⇒ Object
Public: Unpacks given object from payload wrap.
Instance Method Details
#unmarshal(data) ⇒ Object
Public: Unpacks given object from payload wrap.
There are two scenarios for unpacking:
-
Basic value - Just return value or adapt contents (like symbol, arrays or hashes).
-
An object of specific type - Check if our namespace defines such class. No? Erorr. Yes. Unmarshal into.
Returns object unmarshalled.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/stargate/marshal/unmarshaller.rb', line 15 def unmarshal(data) payload = Payload.new(*data) case payload.type.to_sym when Payload::SIMPLE payload.data when Payload::SYMBOL payload.data.to_sym when Payload::LIST unmarshal_list(payload.data) when Payload::HASH unmarshal_hash(payload.data) else klass = payload.type.constantize klass.new(unmarshal_hash(payload.data)) end end |