Create bytes from properties

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

        # Start with the type
        bitstream = BitArray('uint:4=%d' % self.message_type)

        # Add the flags
        bitstream += BitArray('bool=%d' % self.proxy_map_reply)

        # Add reserved bits
        bitstream += self._reserved1

        # Decide on the has_xtr_site_id value
        has_xtr_site_id = bool(self.xtr_id or self.site_id or self.for_rtr)
        bitstream += BitArray('bool=%d, bool=%d' % (has_xtr_site_id,
                                                    self.for_rtr))

        # Add reserved bits
        bitstream += self._reserved2

        # Add the rest of the flags
        bitstream += BitArray('bool=%d' % self.want_map_notify)

        # Add record count
        bitstream += BitArray('uint:8=%d' % len(self.records))

        # Add the nonce
        bitstream += BitArray(bytes=self.nonce)

        # Add the key-id and authentication data
        bitstream += BitArray('uint:16=%d, uint:16=%d, hex=%s'
                              % (self.key_id,
                                 len(self.authentication_data),
                                 self.authentication_data.encode('hex')))

        # Add the map-reply records
        for record in self.records:
            bitstream += record.to_bitstream()

        # Add xTR-ID and site-ID if we said we would
        if has_xtr_site_id:
            bitstream += BitArray('uint:128=%d, uint:64=%d' % (self.xtr_id,
                                                               self.site_id))

        return bitstream.bytes