from typing import Dict
import json
import base64
import binascii


def _encode(doc: Dict) -> str:
    """
    Encode a dictionary (document) as a base64-encoded string.

    :param doc: the dictionary (document) object
    :return: the base64-encoded string
    """
    # Convert the object to a string.
    as_str: str = json.dumps(doc)
    # Encode the string using base64.
    enc_bytes: bytes = base64.b64encode(bytes(as_str, 'utf-8'))
    # Get the ASCII representation of the base64-encoded bytes.
    enc_ascii: bytes = binascii.b2a_base64(enc_bytes, newline=False)
    # Return the string form of the ASCII representation of the base-64
    # encoded bytes.
    return enc_ascii.decode('utf-8')