0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-23 10:11:53 +00:00
bird/mq-scraps/test-encap.py
2023-12-10 14:35:35 +01:00

21 lines
550 B
Python

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])