def to_bytes(self):
        '''
        Create bytes from properties
        '''
        # Verify that the properties make sense
        self.sanitize()

        # Write the next header type
        bitstream = BitStream('uint:8=%d' % self.next_header)

        # Write the header length
        header_length_unpadded = len(self.options) + 2
        header_length = math.ceil(header_length_unpadded / 8.0)
        bitstream += BitStream('uint:8=%d' % (header_length - 1))

        # Add the options
        bitstream += BitStream(bytes=self.options)
        padding_len = (8 - (header_length_unpadded % 8)) % 8
        bitstream += BitStream(padding_len * 8)

        return bitstream.bytes + bytes(self.payload)
def to_bytes ( self ) : self . sanitize ( ) bitstream = BitStream ( 'uint:8=%d' % self . next_header ) header_length_unpadded = len ( self . options ) + 2 header_length = math . ceil ( header_length_unpadded / 8.0 ) bitstream += BitStream ( 'uint:8=%d' % ( header_length - 1 ) ) bitstream += BitStream ( bytes = self . options ) padding_len = ( 8 - ( header_length_unpadded % 8 ) ) % 8 bitstream += BitStream ( padding_len * 8 ) return bitstream . bytes + bytes ( self . payload )
Create bytes from properties