def serialize(self, data: Dict, fields=None, toBytes=True):
        """
        Serializes a dict to bytes preserving the order (in sorted order)
        :param data: the data to be serialized
        :return: serialized data as bytes
        """
        if isinstance(data, Dict):
            data = self._sort_dict(data)
        return msgpack.packb(data, use_bin_type=True)