def serialize()

in datahub/batch/binary_record.py [0:0]


    def serialize(self):
        # record header
        record_head_byte = RecordHeader.serialize(0, self._version_id, self.__get_record_size(), self._next_pos)
        if len(record_head_byte) != RECORD_HEADER_SIZE:
            raise DatahubException("Record header size is {}, should be {}".format(len(record_head_byte), RECORD_HEADER_SIZE))
        self.__append(record_head_byte)

        # field count
        field_count_byte = int2byte(self._field_cnt)
        self.__append(field_count_byte)

        # NullBit: N/8
        for null_bit in self._null_bit:
            null_bit_byte = int2byte(null_bit, size=1, unsigned=True)
            self.__append(null_bit_byte)

        # Field: N*8
        for field_data in self._fields:
            self.__append(field_data)

        # attribute map
        attr_map_len_byte = int2byte(len(self._attr_map))
        self.__append(attr_map_len_byte)

        for key, val in self._attr_map.items():
            key_len_byte = int2byte(len(key))
            self.__append(key_len_byte)
            key_byte = to_binary(key)
            self.__append(key_byte)
            val_len_byte = int2byte(len(val))
            self.__append(val_len_byte)
            val_byte = to_binary(val)
            self.__append(val_byte)
        return self._buffer