native_indexed_store.py (1632B)
1 #!/usr/bin/env python3 2 """Independent indexed wire oracle; historical v1 source-splicing CLI is retired.""" 3 import argparse 4 import hashlib 5 from pathlib import Path 6 import struct 7 8 from executable_object import indexed_manifest 9 from stable_bundle import assembled 10 11 def digest(domain, payload): 12 return hashlib.sha256(domain.encode() + b'\0' + payload).hexdigest() 13 14 15 def indexed_bytes(tree): 16 nodes, seen = [], {} 17 def visit(at): 18 tag, cursor = tree[at], at + 1 19 children = [] 20 for _ in range(tag): 21 child, cursor = visit(cursor) 22 children.append(child) 23 key = (tag, *children) 24 if key not in seen: 25 seen[key] = len(nodes) 26 nodes.append(key) 27 return seen[key], cursor 28 root, consumed = visit(0) 29 assert consumed == len(tree) 30 records = [] 31 for tag, *children in nodes: 32 data = bytes([tag]) + b''.join(struct.pack('>I', child) for child in children) 33 records.append(struct.pack('>I', len(data)) + data) 34 return assembled(indexed_manifest(root), struct.pack('>Q', len(nodes)) + b''.join(records)) 35 36 37 def main(): 38 parser = argparse.ArgumentParser(description=__doc__) 39 parser.add_argument('tricu', type=Path) 40 parser.add_argument('--generation', type=Path, required=True) 41 parser.add_argument('--compiler', type=Path, required=True) 42 parser.add_argument('--directory', type=Path, required=True) 43 parser.parse_args() 44 parser.error("Retired v1 source-splicing probe; use io_indexed.py, io_indexed_write.py and io_compiler_store.py with the current compiler.") 45 46 47 if __name__ == '__main__': main()