this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

parse -> decode

+10 -18
+2 -2
src/atmst/blockstore/car_file.py
··· 1 1 from typing import Dict, List, Tuple, BinaryIO 2 2 import hashlib 3 3 4 - from cbrrr import parse_dag_cbor, CID 4 + from cbrrr import decode_dag_cbor, CID 5 5 6 6 from . import BlockStore 7 7 ··· 51 51 header = file.read(header_len) 52 52 if len(header) != header_len: 53 53 raise EOFError("not enough CAR header bytes") 54 - header_obj = parse_dag_cbor(header) 54 + header_obj = decode_dag_cbor(header) 55 55 if header_obj.get("version") != 1: 56 56 raise ValueError(f"unsupported CAR version ({header_obj.get('version')})") 57 57 if len(header_obj["roots"]) != 1:
+6 -14
src/atmst/cartool.py
··· 2 2 import os 3 3 import base64 4 4 import json 5 - from typing import Tuple, Any, BinaryIO 5 + from typing import Tuple, BinaryIO 6 6 7 - from cbrrr import encode_dag_cbor, parse_dag_cbor, CID 7 + from cbrrr import encode_dag_cbor, decode_dag_cbor, CID 8 8 9 9 from .blockstore.car_file import ReadOnlyCARBlockStore, encode_varint 10 10 from .blockstore import OverlayBlockStore ··· 13 13 from .mst.diff import mst_diff, record_diff 14 14 15 15 16 - class ATJsonEncoder(json.JSONEncoder): 17 - def default(self, o): 18 - if isinstance(o, bytes): 19 - return {"$bytes": base64.b64encode(o).decode()} 20 - if isinstance(o, CID): 21 - return {"$link": o.encode("base32")} 22 - return json.JSONEncoder.default(self, o) 23 - 24 16 def prettify_record(record) -> str: 25 - return json.dumps(record, indent=" ", cls=ATJsonEncoder) 17 + return json.dumps(record, indent=" ") 26 18 27 19 def open_car(car_path: str) -> Tuple[ReadOnlyCARBlockStore, dict]: 28 20 carfile = open(car_path, "rb") 29 21 bs = ReadOnlyCARBlockStore(carfile) 30 - commit = parse_dag_cbor(bs.get_block(bytes(bs.car_root))) 22 + commit = decode_dag_cbor(bs.get_block(bytes(bs.car_root))) 31 23 return bs, commit 32 24 33 25 def print_info(car_path: str) -> None: ··· 51 43 bs, commit = open_car(car_path) 52 44 for k, v in NodeWalker(NodeStore(bs), commit["data"]).iter_kv(): 53 45 if to_json: 54 - record = parse_dag_cbor(bs.get_block(bytes(v))) 46 + record = decode_dag_cbor(bs.get_block(bytes(v)), atjson_mode=True) 55 47 print(f"{json.dumps(k)} -> {prettify_record(record)}") 56 48 else: 57 49 print(f"{json.dumps(k)} -> {v.encode('base32')}") ··· 69 61 if val is None: 70 62 print("Record not found!", file=sys.stderr) 71 63 sys.exit(-1) 72 - record = parse_dag_cbor(bs.get_block(bytes(val))) 64 + record = decode_dag_cbor(bs.get_block(bytes(val)), atjson_mode=True) 73 65 print(prettify_record(record)) 74 66 75 67 def write_block(file: BinaryIO, data: bytes) -> None:
+2 -2
src/atmst/mst/node.py
··· 6 6 from dataclasses import dataclass 7 7 from typing import Tuple, Self, Optional 8 8 9 - from cbrrr import encode_dag_cbor, parse_dag_cbor, CID 9 + from cbrrr import encode_dag_cbor, decode_dag_cbor, CID 10 10 11 11 12 12 @dataclass(frozen=True) # frozen == immutable == win ··· 79 79 80 80 @classmethod 81 81 def deserialise(cls, data: bytes) -> Self: 82 - cbor = parse_dag_cbor(data) 82 + cbor = decode_dag_cbor(data) 83 83 if len(cbor) != 2: # e, l 84 84 raise ValueError("malformed MST node") 85 85 subtrees = [cbor["l"]]