def _parsePayload(self, data):
        '''Parse data and extract this cell's fields.

        Fill in this cell's attributes.

        :param str data: bytes to parse
        '''
        start, end = self.payloadRange()
        offset = start

        if end - start < CERT_TYPE_LEN + CERT_LEN_LEN:
            msg = "CertsCell payload was too few bytes to make a valid "
            msg += "CertsCell."
            raise BadPayloadData(msg)

        self.num_certs = struct.unpack('!B',
                                       data[offset:offset + NUM_CERT_LEN])[0]
        offset += NUM_CERT_LEN
        if self.num_certs > MAX_CERTS_PER_CELL:
            msg = "CertsCell cannot have more than {} certificates per cell."
            msg += " Found {}."
            raise BadPayloadData(msg.format(MAX_CERTS_PER_CELL,
                                            self.num_certs))

        self.cert_payload_items = []

        try:
            for i in xrange(self.num_certs):
                cert_payload_item = CertsCellPayloadItem.parse(data, offset)
                offset += len(cert_payload_item)
                self.cert_payload_items.append(cert_payload_item)
                # catch times when the sender 'lies' and sends a cert
                # larger than the claimed payload length of the cell
                if offset > end:
                    raise IndexError
        except IndexError:
            msg = "CertsCell payload was not enough bytes to construct "
            msg += "a valid CertsCell."
            raise BadPayloadData(msg)
dataset/ETHPy150Open nskinkel/oppy/oppy/cell/varlen.py/CertsCell._parsePayload/original