docs: def encode_payload(cls, payload):
          '''Encode a Python object as JSON and convert it to bytes.'''
          try:
              return json.dumps(payload).encode()
          except TypeError:
              msg = f'JSON payload encoding error: {payload}'
              raise ProtocolError(cls.INTERNAL_ERROR, msg) from None