How can I get the serialized AMF object that rails has rendered

58 views
Skip to first unread message

Chris Brown

unread,
Jan 18, 2011, 12:36:09 PM1/18/11
to rubyamf
Hi,

I've got RubyAMF up and running and have now run into a problem where
I need to the get the serialized amf object on the rails side so I can
pass it to a socket.

It there anyway of getting the amf back from this in the controller?:

render :amf => @my_object

If not how can I manually serialize @my_object to amf?

I hope that makes sense, it's very early in the morning here now and
my brain's stopped working.

Cheers,

Chris

Mark W. Foster

unread,
Jan 18, 2011, 1:46:09 PM1/18/11
to rub...@googlegroups.com
Not sure what you are looking for exactly. RubyAMF takes an object and
converts it into a value object hash VoHash (see util/vo_helper.rb
get_vo_hash_for_outgoing). It serializes the VoHash into a stream as part of
serialization (see write_object in io/amf_serializer.rb) There is no such
thing as manually serializing as the object is directly converted into the
stream to be returned as the last step, and if I am not mistaken, the stream
contains header info, etc. Hope that points you in the right direction.

Mark

Hi,

render :amf => @my_object

Cheers,

Chris

--
You received this message because you are subscribed to the Google Groups
"rubyamf" group.
To post to this group, send email to rub...@googlegroups.com.
To unsubscribe from this group, send email to
rubyamf+u...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyamf?hl=en.

warhammerkid

unread,
Jan 18, 2011, 2:33:39 PM1/18/11
to rubyamf
Chris,

There are two parts to the AMF response. The first is the wrapper,
which includes headers, some time stamps, and whether or not the
request was successful or not. The second part is the serialized
representation of @my_object, or whatever data you're returning.
Typically if you're communicating with flash using sockets and
writeObject/readObject, you would just need the second part, but if
you need both that's a little bit different.

Stephen

Chris Brown

unread,
Jan 18, 2011, 7:47:34 PM1/18/11
to rubyamf
Thanks for the responses guys.

Warhammerkid, as you said I just need the second part, the serialized
object, not all of the HTTP header etc. How can I access that from
inside my rails controller?

Thanks again,

Chris

warhammerkid

unread,
Jan 19, 2011, 10:50:08 AM1/19/11
to rubyamf
Chris,

Assuming that you are using Rails 2, you have two options. If you
don't need the ActiveRecord support provided by RubyAMF, then
RocketAMF (https://github.com/warhammerkid/rocket-amf) is a much
better solution than using RubyAMF. Simply call
RocketAMF.serialize(OBJECT, AMF_VERSION) and you'll get back a string
that you can do whatever you need with. Doing this with RubyAMF is a
little bit more complicated. Here's the code you will use to do that,
as far as I can tell:

amfobj = RubyAMF::AMF::AMFObject.new
ser = RubyAMF::IO::AMFSerializer.new(amfobj)
ser.reset_referencables
ser.write_amf3(OBJECT) # ser.write(OBJECT) for AMF0
serialized_string = amfobj.output_stream

Stephen
Reply all
Reply to author
Forward
0 new messages