From: Maria Matejka Date: Sun, 10 Dec 2023 13:35:35 +0000 (+0100) Subject: some crappy cbor fiddling with ip addresses X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=708ce3f7009f56cdf9bdb72f706084ff7ff2918d;p=thirdparty%2Fbird.git some crappy cbor fiddling with ip addresses --- diff --git a/mq-scraps/test-encap.cbor b/mq-scraps/test-encap.cbor new file mode 100644 index 000000000..32ffd30a2 --- /dev/null +++ b/mq-scraps/test-encap.cbor @@ -0,0 +1 @@ +Ø„Ø6P  ¸4Þ­¾ïÊþúÎþí \ No newline at end of file diff --git a/mq-scraps/test-encap.py b/mq-scraps/test-encap.py new file mode 100644 index 000000000..2778f364c --- /dev/null +++ b/mq-scraps/test-encap.py @@ -0,0 +1,20 @@ +import cbor2 +import json +import ipaddress + +print(cbor2.decoder.semantic_decoders) +print(cbor2.decoder.special_decoders) +cbor2.decoder.semantic_decoders[54] = cbor2.decoder.semantic_decoders[260] + +def testhook(decoder, value): + print(value) + print(value.tag, value.value) + return { + 24: lambda: value, + 54: lambda: ipaddress.IPv6Address(value.value), + }[value.tag]() + +with open("test-encap.cbor", "rb") as sf: + dec = cbor2.CBORDecoder(sf, testhook) + print(data := dec.decode()) + print(data.value[3]) diff --git a/mq-scraps/test-ip.cbor b/mq-scraps/test-ip.cbor new file mode 100644 index 000000000..981a90b02 --- /dev/null +++ b/mq-scraps/test-ip.cbor @@ -0,0 +1 @@ +„Ø6P  ¸4Þ­¾ïÊþúÎþí \ No newline at end of file diff --git a/mq-scraps/test-ip.py b/mq-scraps/test-ip.py new file mode 100644 index 000000000..4868dd1e2 --- /dev/null +++ b/mq-scraps/test-ip.py @@ -0,0 +1,8 @@ +import cbor2 +import json + +with open("test-ip.cbor", "rb") as sf: + loaded = cbor2.load(sf) + +print(loaded) +print(json.dumps(loaded))