code: def encode(self, value):
      "Return a bytestring or bytes-like representation of the value"
      if isinstance(value, (bytes, memoryview)):
          return value
      elif isinstance(value, bool):
          # special case bool since it is a subclass of int
          raise DataError(
              "Invalid input of type: 'bool'. Convert to a "
              "bytes, string, int or float first."
          )
      elif isinstance(value, (int, float)):
          value = repr(value).encode()
      elif not isinstance(value, str):
          # a value we don't know how to deal with. throw an error
          typename = type(value).__name__
          raise DataError(
              f"Invalid input of type: '{typename}'. "
              f"Convert to a bytes, string, int or float first."
          )
      if isinstance(value, str):
          value = value.encode(self.encoding, self.encoding_errors)
      return value
  
imports: from ..exceptions import DataError
label_desc: Use image node_id 2 for calling the Encoder obj's underlying member method code with example usage: obj.encode(value) and returns: value, value