class_docstr: Class to manage Server-Sent Events
class_docstr_tok: ["Class","to","manage","Server-Sent","Events"]
docstr: Encode the message into bytes
  
  :return: The encoded message
docstr_tok: ["Encode","the","message","into","bytes",":","return",":","The","encoded","message"]
code: def encode(self) -> bytes:
      """
      Encode the message into bytes
  
      :return: The encoded message
      """
      buffer = io.StringIO()
      if self.comment is not None:
          for chunk in self.LINE_SEP_EXPR.split(str(self.comment)):
              buffer.write(f": {chunk}")
              buffer.write(self._sep)
  
      if self.id is not None:
          buffer.write(self.LINE_SEP_EXPR.sub("", f"id: {self.id}"))
          buffer.write(self._sep)
  
      if self.event is not None:
          buffer.write(
              self.LINE_SEP_EXPR.sub("", f"event: {self.event}")
          )
          buffer.write(self._sep)
  
      if self.data is not None:
          for chunk in self.LINE_SEP_EXPR.split(json.dumps(self.data)):
              buffer.write(f"data: {chunk}")
              buffer.write(self._sep)
  
      if self.retry is not None:
          if not isinstance(self.retry, int):
              raise TypeError("retry argument must be int")
          buffer.write(f"retry: {self.retry}")
          buffer.write(self._sep)
  
      buffer.write(self._sep)
      return buffer.getvalue().encode("utf-8")
  
imports: import enum
  import io
  import json
  import logging
  import re
  from datetime import datetime
  from functools import partial
  from typing import Any, AsyncIterable, Callable, Coroutine, Dict, Optional, Union
  import anyio
  from starlette.background import BackgroundTask
  from starlette.concurrency import iterate_in_threadpool
  from starlette.responses import Response
  from starlette.types import Receive, Scope, Send
label_desc: Use image node_id 2 for calling the ServerSentEvent obj's underlying member method code with example usage: obj.encode() and returns: buffer