Composer.py 507 Bytes
"""
@author Georg Hopp

"""

import struct

class Composer(object):
    def compose(self, message):
        """
        for now I only encode messages of len less than 126 and
        final...this is just for testing.
        """
        msglen = len(message)
        if msglen > 125:
            raise Exception('messages bigger than 125 bytes not supported')

        frame = struct.pack('BB%ds'%msglen, int('10000010', 2), msglen, message)

        return frame

# vim: set ft=python et ts=8 sw=4 sts=4: