Example #1
0
File: record.py Project: crnt/kdi
def iter_records(f, rver=None):
    off = 0
    bufsz = 1 << 20
    buf = f.read(bufsz)
    end = len(buf)
    while True:
        if off == end:
            buf = f.read(bufsz)
            if not buf:
                return
            off = 0
            end = len(buf)

        if end - off < StructBase._basesizeof(Record, rver):
            x = f.read(bufsz)
            if x == '':
                raise IOError('Unexpected EOF')
            buf = buf[off:] + x
            off = 0
            end = len(buf)
            continue

        r = Record(buf, off, rver)
        sz = r._getsize()
        if end - off < sz:
            x = f.read(bufsz)
            if x == '':
                raise IOError('Unexpected EOF')
            buf = buf[off:] + x
            off = 0
            end = len(buf)
            continue

        off += sz
        yield r
Example #2
0
def iter_records(f, rver=None):
    off = 0
    bufsz = 1 << 20
    buf = f.read(bufsz)
    end = len(buf)
    while True:
        if off == end:
            buf = f.read(bufsz)
            if not buf:
                return
            off = 0
            end = len(buf)
        
        if end - off < StructBase._basesizeof(Record, rver):
            x = f.read(bufsz)
            if x == '':
                raise IOError('Unexpected EOF')
            buf = buf[off:] + x
            off = 0
            end = len(buf)
            continue
        
        r = Record(buf, off, rver)
        sz = r._getsize()
        if end - off < sz:
            x = f.read(bufsz)
            if x == '':
                raise IOError('Unexpected EOF')
            buf = buf[off:] + x
            off = 0
            end = len(buf)
            continue

        off += sz
        yield r
Example #3
0
File: record.py Project: crnt/kdi
def iter_records_string(s, rver=None):
    off = 0
    end = len(s)
    while off < end:
        if end - off < StructBase._basesizeof(Record, rver):
            raise IOError('Partial record header')
        r = Record(s, off, rver)
        sz = r._getsize()
        if end - off < sz:
            raise IOError('Partial record data')
        off += sz
        yield r
Example #4
0
def iter_records_string(s, rver=None):
    off = 0
    end = len(s)
    while off < end:
        if end - off < StructBase._basesizeof(Record, rver):
            raise IOError('Partial record header')
        r = Record(s, off, rver)
        sz = r._getsize()
        if end - off < sz:
            raise IOError('Partial record data')
        off += sz
        yield r
Example #5
0
File: record.py Project: crnt/kdi
 def _sizeof(cls, ver=None):
     baseSize = StructBase._basesizeof(cls, ver)
     return lambda obj: baseSize + obj.length
Example #6
0
 def _sizeof(cls, ver=None):
     baseSize = StructBase._basesizeof(cls, ver)
     return lambda obj: baseSize + obj.length