0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-12 14:18:43 +00:00
bird/yang/json-cbor-yang.py

25 lines
535 B
Python
Raw Normal View History

2023-11-15 11:31:42 +00:00
from yangson import DataModel
import cbor
import json
import sys
class Message:
def __init__(self, filename):
self.filename = filename
with open(self.filename) as sf:
self.raw = json.load(sf)
self.dm = DataModel.from_file('yang-library.json')
self.data = self.dm.from_raw(self.raw)
self.data.validate()
#print(sys.argv[1])
msg = Message(sys.argv[1])
#print(msg, msg.raw)
#print(cbor.dumps(msg.raw))
with open(sys.argv[2], "wb") as of:
cbor.dump(msg.raw, of)
print("OK")