@staticmethod
def _string_bytes_bytearray_as_bytes(src: 'typing.Union[str, bytes, bytearray]'
    ) ->bytes:
    """Get bytes string from string/bytes/bytearray union.

        :param src: source string or bytes-like object
        :return: Byte string
        :rtype: bytes
        :raises TypeError: unexpected source type.
        """
    if isinstance(src, bytes):
        return src
    if isinstance(src, bytearray):
        return bytes(src)
    if isinstance(src, str):
        return src.encode('utf-8')
    raise TypeError(
        f'{src!r} has unexpected type: not conform to Union[str, bytes, bytearray]'
        )
