while True:
    header_text = input.read(record_header.size)
if not header_text:
    break
packet_type, extra_data = record_header.unpack(header_text)
if packet_type == 'w':
    warning_data = warning.unpack(input.read(warning.size))
elif packet_type == 'i':
    info_data = info.unpack(input.read(info.size))
Reading Structure Binary Data in Python?