Module: TorqueBox::Codecs::MarshalSmart

Defined in:
lib/torquebox/codecs/marshal_smart.rb

Constant Summary collapse

MARSHAL_MARKER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"_|marshalled|_"

Class Method Summary collapse

Class Method Details

.decode(object) ⇒ Object



41
42
43
44
45
46
# File 'lib/torquebox/codecs/marshal_smart.rb', line 41

def decode(object)
  if object.is_a?(String) && object.start_with?(MARSHAL_MARKER)
    object = ::Marshal.load(Base64.decode64(object.sub(MARSHAL_MARKER, '')))
  end
  object
end

.encode(object) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/torquebox/codecs/marshal_smart.rb', line 28

def encode(object)
  case object
  when String, Numeric, true, false, nil
    object
  else
    if object.respond_to?(:java_object)
      object
    else
      MARSHAL_MARKER + Base64.encode64(::Marshal.dump(object))
    end
  end
end