mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-23 02:01:55 +00:00
21 lines
550 B
Python
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])
|