0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-09-16 18:35:19 +00:00

some crappy cbor fiddling with ip addresses

This commit is contained in:
Maria Matejka 2023-12-10 14:35:35 +01:00
parent b0f148b86c
commit 708ce3f700
4 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1 @@
и<18>и6P  И4о­ОяЪўњЮўэ

20
mq-scraps/test-encap.py Normal file
View File

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

1
mq-scraps/test-ip.cbor Normal file
View File

@ -0,0 +1 @@
<EFBFBD>и6P  И4о­ОяЪўњЮўэ

8
mq-scraps/test-ip.py Normal file
View File

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