docs: def detect_protocol(cls, message):
          '''Attempt to detect the protocol from the message.'''
          main = cls._message_to_payload(message)
  
          def protocol_for_payload(payload):
              if not isinstance(payload, dict):
                  return JSONRPCLoose   # Will error
              # Obey an explicit "jsonrpc"
              version = payload.get('jsonrpc')
              if version == '2.0':
                  return JSONRPCv2
              if version == '1.0':
                  return JSONRPCv1
  
              # Now to decide between JSONRPCLoose and JSONRPCv1 if possible
              if 'result' in payload and 'error' in payload:
                  return JSONRPCv1
              return JSONRPCLoose
  
          if isinstance(main, list):
              parts = set(protocol_for_payload(payload) for payload in main)
              # If all same protocol, return it
              if len(parts) == 1:
                  return parts.pop()
              # If strict protocol detected, return it, preferring JSONRPCv2.
              # This means a batch of JSONRPCv1 will fail
              for protocol in (JSONRPCv2, JSONRPCv1):
                  if protocol in parts:
                      return protocol
              # Will error if no parts
              return JSONRPCLoose
  
          return protocol_for_payload(main)