def METHOD_NAME(self, object_id, data):
    """Encode object."""
    self.space_left -= 2 + len(data)
    if self.space_left <= 0:
        raise _OutOfSpaceException(object_id)
    encoded_obj = struct.pack(">BB", object_id, len(data))
    if isinstance(data, bytes):
        encoded_obj += data
    else:
        encoded_obj += data.encode()
    self.number_of_objects += 1
    return encoded_obj