mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 09:41:54 +00:00
some crappy cbor fiddling with ip addresses
This commit is contained in:
parent
b0f148b86c
commit
708ce3f700
1
mq-scraps/test-encap.cbor
Normal file
1
mq-scraps/test-encap.cbor
Normal file
@ -0,0 +1 @@
|
|||||||
|
и<18>и6P
И4оОяЪўњЮўэ
|
20
mq-scraps/test-encap.py
Normal file
20
mq-scraps/test-encap.py
Normal 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
1
mq-scraps/test-ip.cbor
Normal file
@ -0,0 +1 @@
|
|||||||
|
<EFBFBD>и6P
И4оОяЪўњЮўэ
|
8
mq-scraps/test-ip.py
Normal file
8
mq-scraps/test-ip.py
Normal 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))
|
Loading…
Reference in New Issue
Block a user