Module: TorqueBox::Codecs::MarshalSmart

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

Constant Summary

MARSHAL_MARKER =
"_|marshalled|_"

Class Method Summary (collapse)

Class Method Details

+ (Object) decode(object)



41
42
43
44
45
46
# File 'core/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

+ (Object) encode(object)



28
29
30
31
32
33
34
35
36
37
38
39
# File 'core/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