def __iter__(self): _, payload = self.S.do(ArchiveListRequest(self.archive_name)) bfr = CornuCopyBuffer([payload]) while not bfr.at_eof(): when = BSString.parse_value(bfr) when = float(when) E = BSString.parse_value(bfr) E = parse(E) if not isinstance(E, _Dirent): raise ValueError("not a _Dirent: %r" % (E, )) yield when, E
def prev_dirent(self): ''' Return the previous Dirent. If not None, during encoding or transcription, if self != prev_dirent, include it in the encoding or transcription. TODO: parse out multiple blockrefs. ''' prev_blockref = self._prev_dirent_blockref if prev_blockref is None: return None bfr = CornuCopyBuffer(prev_blockref) E = _Dirent.from_buffer(bfr) if not bfr.at_eof(): warning( "prev_dirent: _prev_dirent_blockref=%s:" " unparsed bytes after dirent at offset %d", prev_blockref, bfr.offset) return E
def parse(cls, bfr): self = cls() # pylint: disable=attribute-defined-outside-init self.tag_id = bfr.take(4) with Pfx(self.tag_id): size = UInt32BE.parse_value(bfr) self.flags = UInt16BE.parse_value(bfr) if size < 1: warning("size < 1") else: data_bs = bfr.take(size) data_type = self.tag_id_class(self.tag_id) if data_type is None: self.dataframe_body = data_bs else: databfr = CornuCopyBuffer([data_bs]) self.datafrome_body = data_type.parse(databfr) if not databfr.at_eof(): warning("unparsed data: %r" % (databfr.take(...), )) return self
def parse(cls, bfr): self = cls() # pylint: disable=attribute-defined-outside-init self.tag_id = bfr.take(3) with Pfx(self.tag_id): sz0, sz1, sz2 = bfr.take(3) size = sz0 << 16 | sz1 << 8 | sz2 if size < 1: warning("size < 1") else: data_bs = bfr.take(size) if not data_bs or data_bs[0] == 0: # forbidden empty data or data zeroed out data_type = None else: data_type = self.tag_id_class(self.tag_id) if data_type is None: self.value = data_bs else: databfr = CornuCopyBuffer([data_bs]) self.value = data_type.parse(databfr) if not databfr.at_eof(): warning("unparsed data: %r" % (databfr.take(...), )) return self