def decode(args): print('Loading schema...', file=sys.stderr) a = time.time() mod = load_schema(modname=args['SCHEMA'], convert_case=args['--convert-case'], pyx=args['--pyx']) b = time.time() print('schema loaded in %.2f secs' % (b - a), file=sys.stderr) print('decoding stream...', file=sys.stderr) cls = getattr(mod, args['CLASS']) with open(args['FILE'], 'rb') as f: i = 0 while True: try: obj = load(f, cls) except ValueError: break print(obj.shortrepr()) i += 1 if i % 10000 == 0: print(i, file=sys.stderr, end='\r') c = time.time() print('\nstream decoded in %.2f secs' % (c - b), file=sys.stderr)
def decode(args): print >> sys.stderr, 'Loading schema...' a = time.time() mod = load_schema(args['SCHEMA'], convert_case=args['--convert-case'], pyx=args['--pyx']) b = time.time() print >> sys.stderr, 'schema loaded in %.2f secs' % (b - a) print >> sys.stderr, 'decoding stream...' cls = getattr(mod, args['CLASS']) with open(args['FILE']) as f: i = 0 while True: try: obj = load(f, cls) except ValueError: break print obj.shortrepr() i += 1 if i % 10000 == 0: print >> sys.stderr, i c = time.time() print >> sys.stderr, 'stream decoded in %.2f secs' % (c - b)
int32, int64, uint8, uint16, uint32, uint64, float32, float64, text, group, inner, intlist, color) Point = namedtuple('Point', ['x', 'y', 'z']) StrPoint = namedtuple('StrPoint', ['x', 'y', 'z']) Rectangle = namedtuple('Rectangle', ['a', 'b']) MyStructContainer = namedtuple('MyStructContainer', ['items']) MyInt64List = namedtuple('MyInt64List', ['items']) # ============================================================ # capnpy storage # ============================================================ Capnpy = capnpy.load_schema('capnpy.benchmarks.benchmarks') # ============================================================ # pycapnp storage # ============================================================ try: import capnp as pycapnp except ImportError: pycapnp = None else: thisdir = py.path.local(__file__).dirpath() rootdir = thisdir.dirpath('..') pycapnp_schema = pycapnp.load(str(thisdir.join('benchmarks.capnp')), imports=[str(rootdir)])