Permalink
Browse files

Fix struct serialization problem

  • Loading branch information...
divoxx committed Oct 5, 2009
1 parent d874a0a commit 561f52b1c82105b253cd618604bebc94e7224804
@@ -23,6 +23,11 @@ def run(object)
"a:#{object.length}:{#{items}}"
else
klass_name = object.class.name
+
+ if klass_name =~ /^Struct::/ && php_klass = object.instance_variable_get("@_php_class")
+ klass_name = php_klass
+ end
+
attributes = object.instance_variables.map { |var_name| "#{run(var_name.gsub(/^@/, ''))}#{run(object.instance_variable_get(var_name))}" }
"O:#{klass_name.length}:\"#{klass_name}\":#{object.instance_variables.length}:{#{attributes}}"
end

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -27,14 +27,16 @@ rule
object : 'O' ':' NUMBER ':' STRING ':' NUMBER ':' '{' attribute_list '}'
{
- if Object.const_defined?(val[4])
+ if eval("defined?(#{val[4]})")
result = Object.const_get(val[4]).new
val[9].each do |(attr_name, value)|
result.instance_variable_set("@#{attr_name.gsub(/(^\*)|\0/, '')}", value)
end
else
- result = Struct.new(val[4], *val[9].map { |(k,v)| k.gsub(/(^\*)|\0/, '').to_sym }).new(*val[9].map { |(k,v)| v })
+ klass_name = val[4].gsub(/^Struct::/, '')
+ result = Struct.new(klass_name, *val[9].map { |(k,v)| k.gsub(/(^\*)|\0/, '').to_sym }).new(*val[9].map { |(k,v)| v })
+ result.instance_variable_set("@_php_class", klass_name)
end
}
;

0 comments on commit 561f52b

Please sign in to comment.