cultcache-py: MessagePack is the default payload; PayloadCodec; convert (py-msgpack-default) (#179)
This commit is contained in:
parent
0df5036ffa
commit
7bbc56f5dd
15 changed files with 1601 additions and 93 deletions
|
|
@ -14,7 +14,7 @@ raw = msgpack.unpackb(open(path, "rb").read(), raw=False)
|
|||
print("store header", raw[0], "catalog entry", raw[1][0][:5] if raw[1] else None)
|
||||
print("record", raw[2][0][:3], "payload", raw[2][0][3][:40])
|
||||
# MessagePack-default reader, today's _messagepack pair standing in for the proposed default
|
||||
new = cc.define_document_type("brokkr.sync.var.v0", payload_encoder=lambda t: msgpack.packb(t, use_bin_type=True), payload_decoder=lambda b: msgpack.unpackb(b, raw=False))
|
||||
new = cc.define_document_type("brokkr.sync.var.v0") # historical: the probe stood a msgpack pair in for the proposed default, now the default
|
||||
try: open_cache(new); print("new reader: ACCEPTED")
|
||||
except Exception as e: print("new reader refused:", type(e).__module__, type(e).__name__, str(e)[:80])
|
||||
# opt-in JSON pair reads it
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import sys, os
|
|||
sys.path.insert(0, r"F:\Projects\CultLib\packages\cultcache-py\src"); sys.path.insert(0, os.path.dirname(__file__))
|
||||
import proto_leaves as L
|
||||
from cultcache_py import CultCache, SingleFileMessagePackBackingStore
|
||||
from cultcache_py.documents import define_document_type
|
||||
from cultcache_py.documents import PayloadCodec, define_document_type
|
||||
from cultcache_py.backing_store import CultCacheSchemaCatalogMember as M
|
||||
|
||||
NS = "GameCult.Caching.Tests.PyLeavesProbe"
|
||||
|
|
@ -25,7 +25,7 @@ def payload(doc_id):
|
|||
def write(path, members, tree_for):
|
||||
doc = define_document_type(
|
||||
"cultcache.py-leaves-probe", encode=lambda v: v, decode=lambda v: v,
|
||||
payload_encoder=L.write, payload_decoder=lambda b: b, name=lambda v: v[0],
|
||||
payload_codec=PayloadCodec("leaves-probe", L.write, lambda b: b), name=lambda v: v[0],
|
||||
schema_name="cultcache.py-leaves-probe", schema_version="cultcache.py_leaves_probe.v1",
|
||||
members=[M(slot=s, member_name=n, type_name=t, is_name=(s == 0)) for s, n, t in members])
|
||||
if os.path.exists(path): os.remove(path)
|
||||
|
|
|
|||
Loading…
Reference in a new issue