code: def _parse_header_format(self, buffer):
      # make BufferIO look like TTransport for varint helpers
      buffer_transport = TMemoryBuffer()
      buffer_transport._buffer = buffer
  
      buffer.read(2)  # discard the magic bytes
      (self.flags,) = U16.unpack(buffer.read(U16.size))
      (self.sequence_id,) = I32.unpack(buffer.read(I32.size))
  
      header_length = U16.unpack(buffer.read(U16.size))[0] * 4
      end_of_headers = buffer.tell() + header_length
      if end_of_headers > len(buffer.getvalue()):
          raise TTransportException(
              TTransportException.SIZE_LIMIT,
              "Header size is larger than whole frame.",
          )
  
      self._protocol_id = readVarint(buffer_transport)
  
      transforms = []
      transform_count = readVarint(buffer_transport)
      for _ in range(transform_count):
          transform_id = readVarint(buffer_transport)
          if transform_id not in READ_TRANSFORMS_BY_ID:
              raise TApplicationException(
                  TApplicationException.INVALID_TRANSFORM,
                  "Unknown transform: %d" % transform_id,
              )
          transforms.append(transform_id)
      transforms.reverse()
  
      headers = {}
      while buffer.tell() < end_of_headers:
          header_type = readVarint(buffer_transport)
          if header_type == TInfoHeaderType.KEY_VALUE:
              count = readVarint(buffer_transport)
              for _ in range(count):
                  key = _readString(buffer_transport)
                  value = _readString(buffer_transport)
                  headers[key] = value
          else:
              break  # ignore unknown headers
      self._read_headers = headers
  
      # skip padding / anything we didn't understand
      buffer.seek(end_of_headers)
  
      payload = buffer.read()
      for transform_id in transforms:
          transform_fn = READ_TRANSFORMS_BY_ID[transform_id]
          payload = transform_fn(payload)
      return BufferIO(payload)
  
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 14 for calling the THeaderTransport obj's underlying member method code with example usage: obj._parse_header_format(buffer) and returns: BufferIO