Example #1
0
    def test_encode(self):
        stream = util.BufferedByteStream()
        encoder = amf3.Encoder(stream)

        x = flex.ArrayCollection()

        x['spam'] = 'eggs'

        encoder.writeElement(x)

        self.assertEquals(
            stream.getvalue(), '\n\x07Cflex.messaging.io.ArrayCollection'
            '\t\x01\tspam\x06\teggs\x01')

        stream = util.BufferedByteStream()
        encoder = amf0.Encoder(stream)

        x = flex.ArrayCollection()

        x['spam'] = 'eggs'

        encoder.writeElement(x)

        self.assertEquals(
            stream.getvalue(),
            '\x11\n\x07Cflex.messaging.io.ArrayCollection\t\x01\tspam\x06\x09'
            'eggs\x01')
Example #2
0
    def write(self, message):
        log.debug('send %r', message)
        """ Encode and write the specified message into the stream. """
        datatype = message['msg']
        body_stream = pyamf.util.BufferedByteStream()
        encoder = amf0.Encoder(body_stream)

        if datatype == rtmp_type.DT_USER_CONTROL:
            body_stream.write_ushort(message['event_type'])
            body_stream.write(message['event_data'])
            self.send_msg(datatype, body_stream.getvalue())

        elif datatype == rtmp_type.DT_WINDOW_ACK_SIZE:
            body_stream.write_ulong(message['window_ack_size'])
            self.send_msg(datatype, body_stream.getvalue())

        elif datatype == rtmp_type.DT_SET_PEER_BANDWIDTH:
            body_stream.write_ulong(message['window_ack_size'])
            body_stream.write_uchar(message['limit_type'])
            self.send_msg(datatype, body_stream.getvalue())

        elif datatype == rtmp_type.DT_COMMAND:
            for command in message['command']:
                encoder.writeElement(command)
            if 'closeStream' in message['command']:
                self.send_msg(datatype,
                              body_stream.getvalue(),
                              stream_id=self.stream_id)
            elif 'deleteStream' in message['command']:
                self.send_msg(datatype,
                              body_stream.getvalue(),
                              stream_id=self.stream_id)
            elif 'publish' in message['command']:
                self.send_msg(datatype,
                              body_stream.getvalue(),
                              stream_id=self.stream_id)
            elif 'play' in message['command']:
                self.send_msg(datatype,
                              body_stream.getvalue(),
                              chunk_id=8,
                              stream_id=self.stream_id)
            else:
                self.send_msg(datatype, body_stream.getvalue())

        elif datatype == rtmp_type.DT_AMF3_COMMAND:
            encoder = amf3.Encoder(body_stream)
            for command in message['command']:
                encoder.writeElement(command)
            self.send_msg(datatype, body_stream.getvalue())

        elif datatype == rtmp_type.DT_SHARED_OBJECT:
            encoder.serialiseString(message['obj_name'])
            body_stream.write_ulong(message['curr_version'])
            body_stream.write(message['flags'])

            for event in message['events']:
                self.write_shared_object_event(event, body_stream)
            self.send_msg(datatype, body_stream.getvalue())
        else:
            assert False, message
Example #3
0
    def test_encode_amf3(self):
        stream = util.BufferedByteStream()
        encoder = amf3.Encoder(stream)

        x = flex.ArrayCollection()
        x.append('eggs')

        encoder.writeElement(x)

        self.assertEquals(stream.getvalue(),
            '\n\x07Cflex.messaging.io.ArrayCollection\t\x03\x01\x06\teggs')
Example #4
0
    def test_encode(self):
        stream = util.BufferedByteStream()
        encoder = amf3.Encoder(stream)

        x = flex.ObjectProxy(pyamf.MixedArray(a='spam', b=5))

        encoder.writeElement(x)

        self.assertTrue(check_buffer(stream.getvalue(), (
            '\n\x07;flex.messaging.io.ObjectProxy\t\x01',
            ('\x03a\x06\x09spam', '\x03b\x04\x05'), '\x01')))
Example #5
0
    def test_encode(self):
        stream = util.BufferedByteStream()
        encoder = amf3.Encoder(stream)

        x = flex.ObjectProxy(pyamf.MixedArray(a='spam', b=5))

        encoder.writeElement(x)

        self.assertEquals(
            stream.getvalue(),
            '\x0a\x07;flex.messaging.io.ObjectProxy\x09\x01\x03a\x06\x09spam'
            '\x03b\x04\x05\x01')