[pyamf-users] Encoding question.
hernan
hernanpub at gmail.com
Thu Sep 11 11:13:07 CEST 2008
Hi pyAMF users,
I have a few packets captured from my Flash application and I want to
be able to produce messages with the same structure using pyamf (for
load testing). So far I haven't had much luck doing so. Here's a bit
of detail:
------------------------
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open('login_usertest5_02.bin')
>>> data = f.read()
>>> data
'\x00\x03\x00\x00\x00\x01\x00\x04null\x00\x02/2\x00\x00\x01\x18\n\x00\x00\x00\x01\x11\n\x81\x13Oflex.messaging.messages.RemotingMessage\x13operation\rsource\x13messageId\x11clientId\x15timeToLive\x13timestamp\x0fheaders\x17destination\tbody\x06\x0blogin\x01\x06I3A3AD218-3EE0-F812-3A73-3B6BC3564797\x01\x04\x00\x04\x00\n\x0b\x01\tDSId\x06I33EB4068-BA5D-45F4-A51B-188584646BDC\x15DSEndpoint\x06\x17def-channel\x01\x06\x0fuserWeb\t\x05\x01\x06\x17user.test.5\x06"'
>>> import pyamf
>>> import pyamf.remoting
>>> obj = pyamf.remoting.decode(data)
>>> obj
<Envelope amfVersion=0 clientType=3>
(u'/2', <Request target=null>[<RemotingMessage body=[u'user.test.5',
u'user.test.5'] source=None timestamp=0 destination=u'userWeb'
clientId=None headers={'DSId':
u'33EB4068-BA5D-45F4-A51B-188584646BDC', 'DSEndpoint': u'def-channel'}
timeToLive=0 messageId=u'3A3AD218-3EE0-F812-3A73-3B6BC3564797'
operation=u'login' />]</Request>)
</Envelope>
>>>
------------------------
So far, so good. pyAMF decodes one of my sample binary packets and
the information in it is exactly what I expect. I try to take the
decoded message and re-encode it just as a sanity check:
------------------------
>>> newblob = pyamf.remoting.encode(result).getvalue()
>>> newblob
'\x00\x03\x00\x00\x00\x01\x00\x04null\x00\x02/2\x00\x00\x00\x00\n\x00\x00\x00\x01\x11\n\x0bOflex.messaging.messages.RemotingMessage\tbody\t\x05\x01\x06\x17user.test.5\x06\x04\rsource\x01\x13timestamp\x04\x00\x17destination\x06\x0fuserWeb\x11clientId\x01\x0fheaders\n\x0b\x01\tDSId\x06I33EB4068-BA5D-45F4-A51B-188584646BDC\x15DSEndpoint\x06\x17def-channel\x01\x15timeToLive\x04\x00\x13messageId\x06I3A3AD218-3EE0-F812-3A73-3B6BC3564797\x13operation\x06\x0blogin\x01'
------------------------
So obviously the object serializes to a different binary
representation and that's not completely unexpected since there are
various options controlling serialization. What I tried to do next is
come up with the right code to build this message from scratch and
hopefully arrive at the serialized format I need.
------------------------
AMFVER = pyamf.AMF0
CLIENT_TYPE = pyamf.ClientTypes.Flash9
URL='http://test.defy.org/app'
message = messaging.RemotingMessage(
body=[u'user.test.4',u'user.test.4'],
source=None,
operation=u'login',
messageId=u'3A3AD218-3EE0-F812-3A73-3B6BC3564797',
timeToLive=0,
timestamp=0,
headers={u'DSEndpoint':'def-channel',u'DSId':'33EB4068-BA5D-45F4-A51B-188584646BDC'},
destination=u'userWeb',
clientId=None
)
my_envelope = Envelope(AMFVER,CLIENT_TYPE)
request = Request(target="null",body=[message],envelope=my_envelope)
my_envelope['/1'] = request
x = pyamf.remoting.encode(my_envelope).getvalue()
------------------------
When I run this through the interpreter I get the following result:
------------------------
>>> x
'\x00\x03\x00\x00\x00\x01\x00\x04null\x00\x02/1\x00\x00\x00\x00\n\x00\x00\x00\x01\x11\n\x0bOflex.messaging.messages.RemotingMessage\tbody\t\x05\x01\x06\x17user.test.4\x06\x04\rsource\x01\x13timestamp\x04\x00\x17destination\x06\x0fuserWeb\x11clientId\x01\x0fheaders\n\x0b\x01\tDSId\x06I33EB4068-BA5D-45F4-A51B-188584646BDC\x15DSEndpoint\x06\x17def-channel\x01\x15timeToLive\x04\x00\x13messageId\x06I3A3AD218-3EE0-F812-3A73-3B6BC3564797\x13operation\x06\x0blogin\x01'
>>>
------------------------
This is the same as the new blob above which is good, I have the right
content but still not the serialization I need. After comparing the
messages produced by my application with those produced by
pyamf.remoting.encode(), I think the issue might have to do with
ObjectCoding DYNAMIC vs. ObjectCoding.STATIC but I'm not sure how give
pyAMF the necessary hints to get it to behave differently.
I appreciate any help I can get on this issue, thanks in advance!
hs
san francisco, ca
More information about the users
mailing list