code: def _decode_record(self, s, line=0):
          '''Decode one record of HEX file.
          @param  s       line with HEX record.
          @param  line    line number (for error messages).
          @raise  EndOfFile   if EOF record encountered.
          '''
          s = s.rstrip('\r\n')
          if not s:
              return
          if s[0] == ':':
              try:
                  bin = array('B', unhexlify(asbytes(s[1:])))
              except (TypeError, ValueError):
                  raise HexRecordError(line=line)
              length = len(bin)
              if length < 5:
                  raise HexRecordError(line=line)
          else:
              raise HexRecordError(line=line)
          record_length = bin[0]
          if length != (5 + record_length):
              raise RecordLengthError(line=line)
          addr = bin[1]*256 + bin[2]
          record_type = bin[3]
          if not (0 <= record_type <= 5):
              raise RecordTypeError(line=line)
          crc = sum(bin)
          crc &= 0x0FF
          if crc != 0:
              raise RecordChecksumError(line=line)
          if record_type == 0:
              addr += self._offset
              for i in range_g(4, 4+record_length):
                  if not self._buf.get(addr, None) is None:
                      raise AddressOverlapError(address=addr, line=line)
                  self._buf[addr] = bin[i]
                  addr += 1
          elif record_type == 1:
              if record_length != 0:
                  raise EOFRecordError(line=line)
              raise _EndOfFile
          elif record_type == 2:
              if record_length != 2 or addr != 0:
                  raise ExtendedSegmentAddressRecordError(line=line)
              self._offset = (bin[4]*256 + bin[5]) * 16
          elif record_type == 4:
              if record_length != 2 or addr != 0:
                  raise ExtendedLinearAddressRecordError(line=line)
              self._offset = (bin[4]*256 + bin[5]) * 65536
          elif record_type == 3:
              if record_length != 4 or addr != 0:
                  raise StartSegmentAddressRecordError(line=line)
              if self.start_addr:
                  raise DuplicateStartAddressRecordError(line=line)
              self.start_addr = {'CS': bin[4]*256 + bin[5],
                                 'IP': bin[6]*256 + bin[7],
                                }
          elif record_type == 5:
              if record_length != 4 or addr != 0:
                  raise StartLinearAddressRecordError(line=line)
              if self.start_addr:
                  raise DuplicateStartAddressRecordError(line=line)
              self.start_addr = {'EIP': (bin[4]*16777216 +
                                         bin[5]*65536 +
                                         bin[6]*256 +
                                         bin[7]),
                                }