code: def readFrame(self, req_sz):
      # the first word could either be the length field of a framed message
      # or the first bytes of an unframed message.
      first_word = self._transport.readAll(I32.size)
      (frame_size,) = I32.unpack(first_word)
      is_unframed = False
      if (
          frame_size & TBinaryProtocol.VERSION_MASK
          == TBinaryProtocol.VERSION_1
      ):
          self._set_client_type(THeaderClientType.UNFRAMED_BINARY)
          is_unframed = True
      elif (
          byte_index(first_word, 0) == TCompactProtocol.PROTOCOL_ID
          and byte_index(first_word, 1) & TCompactProtocol.VERSION_MASK
          == TCompactProtocol.VERSION
      ):
          self._set_client_type(THeaderClientType.UNFRAMED_COMPACT)
          is_unframed = True
  
      if is_unframed:
          bytes_left_to_read = req_sz - I32.size
          if bytes_left_to_read > 0:
              rest = self._transport.read(bytes_left_to_read)
          else:
              rest = b""
          self._read_buffer = BufferIO(first_word + rest)
          return
  
      # ok, we're still here so we're framed.
      if frame_size > self._max_frame_size:
          raise TTransportException(
              TTransportException.SIZE_LIMIT,
              "Frame was too large.",
          )
      read_buffer = BufferIO(self._transport.readAll(frame_size))
  
      # the next word is either going to be the version field of a
      # binary/compact protocol message or the magic value + flags of a
      # header protocol message.
      second_word = read_buffer.read(I32.size)
      (version,) = I32.unpack(second_word)
      read_buffer.seek(0)
      if version >> 16 == HEADER_MAGIC:
          self._set_client_type(THeaderClientType.HEADERS)
          self._read_buffer = self._parse_header_format(read_buffer)
      elif (
          version & TBinaryProtocol.VERSION_MASK
          == TBinaryProtocol.VERSION_1
      ):
          self._set_client_type(THeaderClientType.FRAMED_BINARY)
          self._read_buffer = read_buffer
      elif (
          byte_index(second_word, 0) == TCompactProtocol.PROTOCOL_ID
          and byte_index(second_word, 1) & TCompactProtocol.VERSION_MASK
          == TCompactProtocol.VERSION
      ):
          self._set_client_type(THeaderClientType.FRAMED_COMPACT)
          self._read_buffer = read_buffer
      else:
          raise TTransportException(
              TTransportException.INVALID_CLIENT_TYPE,
              "Could not detect client transport type.",
          )
  
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 13 for calling the THeaderTransport obj's underlying member method code with example usage: obj.readFrame(req_sz) without return types