code: def _as_bytes(bytes_or_text: Union[bytearray, bytes, str]) -> bytes:
      """Converts `bytearray`, `bytes`, or unicode python input types to `bytes`.
  
      Uses utf-8 encoding for text by default.
  
      Args:
        bytes_or_text: A `bytearray`, `bytes`, `str`, or `unicode` object.
  
      Returns:
        A `bytes` object.
  
      Raises:
        TypeError: If `bytes_or_text` is not a binary or unicode string.
      """
      # Validate encoding, a LookupError will be raised if invalid.
      if isinstance(bytes_or_text, (bytearray, bytes)):
          return bytes_or_text
      elif isinstance(bytes_or_text, str):
          return bytes_or_text.encode(encoding="utf-8")
      else:
          raise TypeError(
              "Expected binary or unicode string, got %r"
              % (bytes_or_text,)
          )
  
imports: from __future__ import annotations
  import abc
  import collections
  import dataclasses
  from typing import Any, Mapping, Union
  import numpy
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core.features import feature
  from tensorflow_datasets.core.utils import dtype_utils
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
  from tensorflow_datasets.proto import tf_example_pb2
  from tensorflow_datasets.proto import tf_feature_pb2
label_desc: Use image node_id 5 for calling a global function with example usage: _as_bytes(bytes_or_text) and returns: bytes_or_text, bytes_or_text