from typing import List
import ctypes


def EncodeAsCUbytes(*values: int) -> List[ctypes.c_ubyte]:
  """Encodes the argument ints as a list of ctypes.c_ubyte.

  We encode as ctypes.c_ubyte because that type is guaranteed to be one byte in
  size when encoded as binary. This function validates that the inputs are
  within the range that can be represented as bytes.

  Argument:
    values: Integers in range [0, 255].

  Returns:
    List of c_ubyte.
  """
  for i, value in enumerate(values):
    if not 0 <= value <= 255:
      raise ValueError('value = %d out of bounds at byte %d' % (value, i))
  return [ctypes.c_ubyte(value) for value in values]