code: def flush(self):
      payload = self._write_buffer.getvalue()
      self._write_buffer = BufferIO()
  
      buffer = BufferIO()
      if self._client_type == THeaderClientType.HEADERS:
          for transform_id in self._write_transforms:
              transform_fn = WRITE_TRANSFORMS_BY_ID[transform_id]
              payload = transform_fn(payload)
  
          headers = BufferIO()
          writeVarint(headers, self._protocol_id)
          writeVarint(headers, len(self._write_transforms))
          for transform_id in self._write_transforms:
              writeVarint(headers, transform_id)
          if self._write_headers:
              writeVarint(headers, TInfoHeaderType.KEY_VALUE)
              writeVarint(headers, len(self._write_headers))
              for key, value in self._write_headers.items():
                  _writeString(headers, key)
                  _writeString(headers, value)
              self._write_headers = {}
          padding_needed = (4 - (len(headers.getvalue()) % 4)) % 4
          headers.write(b"\x00" * padding_needed)
          header_bytes = headers.getvalue()
  
          buffer.write(I32.pack(10 + len(header_bytes) + len(payload)))
          buffer.write(U16.pack(HEADER_MAGIC))
          buffer.write(U16.pack(self.flags))
          buffer.write(I32.pack(self.sequence_id))
          buffer.write(U16.pack(len(header_bytes) // 4))
          buffer.write(header_bytes)
          buffer.write(payload)
      elif self._client_type in (
          THeaderClientType.FRAMED_BINARY,
          THeaderClientType.FRAMED_COMPACT,
      ):
          buffer.write(I32.pack(len(payload)))
          buffer.write(payload)
      elif self._client_type in (
          THeaderClientType.UNFRAMED_BINARY,
          THeaderClientType.UNFRAMED_COMPACT,
      ):
          buffer.write(payload)
      else:
          raise TTransportException(
              TTransportException.INVALID_CLIENT_TYPE,
              "Unknown client type.",
          )
  
      # the frame length field doesn't count towards the frame payload size
      frame_bytes = buffer.getvalue()
      frame_payload_size = len(frame_bytes) - 4
      if frame_payload_size > self._max_frame_size:
          raise TTransportException(
              TTransportException.SIZE_LIMIT,
              "Attempting to send frame that is too large.",
          )
  
      self._transport.write(frame_bytes)
      self._transport.flush()
  
imports: import struct
  import zlib
  from thrift.compat import BufferIO, byte_index
  from thrift.protocol.TBinaryProtocol import TBinaryProtocol
  from thrift.protocol.TCompactProtocol import TCompactProtocol, readVarint, writeVarint
  from thrift.Thrift import TApplicationException
  from thrift.transport.TTransport import CReadableTransport, TMemoryBuffer, TTransportBase, TTransportException
label_desc: Use image node_id 16 for calling the THeaderTransport obj's underlying member method code with example usage: obj.flush() without return types