Skip to content

ark_model

base64_serializer(data)

Serializes a dictionary to a base64-encoded JSON string.

Parameters:

Name Type Description Default
data Dict[str, Any]

The dictionary to serialize.

required

Returns:

Name Type Description
str str

The base64-encoded JSON string.

Raises:

Type Description
ArkException

If there is an error during serialization.

Source code in ark_sdk_python/models/ark_model.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def base64_serializer(data: Dict[str, Any]) -> str:
    """
    Serializes a dictionary to a base64-encoded JSON string.

    Args:
        data (Dict[str, Any]): The dictionary to serialize.

    Returns:
        str: The base64-encoded JSON string.

    Raises:
        ArkException: If there is an error during serialization.
    """
    try:
        json_bytes = json.dumps(data).encode('utf-8')
        base64_bytes = base64.b64encode(json_bytes)
        return base64_bytes.decode('utf-8')
    except (TypeError, ValueError) as e:
        raise ArkException(f'Error encoding data to base64: {e}') from e