code: def decode(self, line: str) -> ServerSentEvent | None:
      # See: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation  # noqa: E501
  
      if not line:
          if (
              not self._event
              and not self._data
              and not self._last_event_id
              and self._retry is None
          ):
              return None
  
          sse = ServerSentEvent(
              event=self._event,
              data="\n".join(self._data),
              id=self._last_event_id,
              retry=self._retry,
          )
  
          # NOTE: as per the SSE spec, do not reset last_event_id.
          self._event = None
          self._data = []
          self._retry = None
  
          return sse
  
      if line.startswith(":"):
          return None
  
      fieldname, _, value = line.partition(":")
  
      if value.startswith(" "):
          value = value[1:]
  
      if fieldname == "event":
          self._event = value
      elif fieldname == "data":
          self._data.append(value)
      elif fieldname == "id":
          if "\0" in value:
              pass
          else:
              self._last_event_id = value
      elif fieldname == "retry":
          try:
              self._retry = int(value)
          except (TypeError, ValueError):
              pass
      else:
          pass  # Field is ignored.
  
      return None
  
imports: from __future__ import annotations
  import json
  from types import TracebackType
  from typing import TYPE_CHECKING, Any, Generic, TypeVar, Iterator, AsyncIterator, cast
  from typing_extensions import Self, override
  import httpx
  from ._utils import is_mapping
  from ._exceptions import APIError
label_desc: Use image node_id 3 for calling the SSEDecoder obj's underlying member method code with example usage: obj.decode(line) and returns: None, sse, None, None