code: def decode(f):
          
          decoder = mqtt_io.FileDecoder(f)
          (byte_0,) = decoder.unpack(mqtt_io.FIELD_U8)
  
          packet_type_u4 = (byte_0 >> 4)
          flags = byte_0 & 0x0f
  
          try:
              packet_type = MqttControlPacketType(packet_type_u4)
          except ValueError:
              raise DecodeError('Unknown packet type 0x{:02x}.'.format(packet_type_u4))
  
          if not are_flags_valid(packet_type, flags):
              raise DecodeError('Invalid flags for packet type.')
  
          num_bytes, num_remaining_bytes = decoder.unpack_varint(4)
  
          return decoder.num_bytes_consumed, MqttFixedHeader(packet_type, flags, num_remaining_bytes)
docs: Extract a `MqttFixedHeader` from ``f``.
  
          Parameters
          ----------
          f: file
              Object with read method.
  
          Raises
          -------
          DecodeError
              When bytes decoded have values incompatible with a
              `MqttFixedHeader` object.
          UnderflowDecodeError
              When end-of-stream is encountered before the end of the
              fixed header.
  
          Returns
          -------
          int
              Number of bytes consumed from ``f``.
          MqttFixedHeader
              Header object extracted from ``f``.