Skip to content

Instantly share code, notes, and snippets.

@njoyce
Created September 30, 2010 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njoyce/603940 to your computer and use it in GitHub Desktop.
Save njoyce/603940 to your computer and use it in GitHub Desktop.
import pyamf
class TestProtocol(object):
def connectionMade(self):
self.decoder = pyamf.get_decoder(pyamf.AMF0)
self.buffer = self.decoder.stream
self.context = self.decoder.context
def dataReceived(self, data):
self.buffer.append(data) # adds data to the end of the stream without changing the current position of the stream
try:
amf_object = self.decoder.readElement()
except IOError:
# not enough data to decode a fully crafted AMF object
# the stream is reset back to its original position - see http://github.com/hydralabs/pyamf/blob/master/pyamf/codec.py#L342
except:
# something went wrong whilst decoding the AMF, now we log and die.
# todo ... logging :)
self.transport.loseConnection()
else:
# consumes the already decoded data from the stream
self.stream.consume()
# AMF uses references which we need to clear after each raw AMF object sent from Flash.
self.context.clear()
# do something with amf_object here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment