Created
September 30, 2010 02:51
-
-
Save njoyce/603940 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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