--- /dev/null
+from yangson import DataModel
+
+import cbor
+import json
+
+class Message:
+ def __init__(self, filename, _type):
+ self.filename = filename
+ with open(self.filename, "rb") as sf:
+ self.raw = { "json": json, "cbor": cbor }[_type].load(sf)
+
+ self.dm = DataModel.from_file('yang-library.json')
+ self.data = self.dm.from_raw(self.raw)
+ self.data.validate()
--- /dev/null
+python3 -m venv venv
+. venv/bin/activate
+pip3 install yangson cbor
+
+python3 cbor-json-yang.py "$@"
--- /dev/null
+import cbor
+import json
+import sys
+
+import JSON_CBOR
+
+#print(sys.argv[1])
+
+msg = JSON_CBOR.Message(sys.argv[1], "cbor")
+with open(sys.argv[2], "w") as of:
+ json.dump(msg.raw, of, indent=2)
+
+print("OK")
pip3 install yangson cbor
python3 json-cbor-yang.py "$@"
-#python3 json2cbor.py "$@"
-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()
+import JSON_CBOR
#print(sys.argv[1])
-msg = Message(sys.argv[1])
-#print(msg, msg.raw)
-#print(cbor.dumps(msg.raw))
+msg = JSON_CBOR.Message(sys.argv[1], "json")
with open(sys.argv[2], "wb") as of:
cbor.dump(msg.raw, of)
{
"show_memory:message": {
- "header": "BIRD memory usage",
- "body": {
- "routing_tables": {
- "effective": 324,
- "overhead": 48
- },
- "route_attributes": {
- "effective": 324,
- "overhead": 48
- },
- "protocols": {
- "effective": 324,
- "overhead": 48
- },
- "current_config": {
- "effective": 324,
- "overhead": 48
- },
- "standby_memory": {
- "effective": 324,
- "overhead": 48
- },
- "total": {
- "effective": 324,
- "overhead": 48
- }
- }
+ "header": "BIRD memory usage",
+ "body": {
+ "routing_tables": {
+ "effective": 324,
+ "overhead": 48
+ },
+ "route_attributes": {
+ "effective": 324,
+ "overhead": 48
+ },
+ "protocols": {
+ "effective": 324,
+ "overhead": 48
+ },
+ "current_config": {
+ "effective": 324,
+ "overhead": 48
+ },
+ "standby_memory": {
+ "effective": 324,
+ "overhead": 48
+ },
+ "total": {
+ "effective": 324,
+ "overhead": 48
+ }
+ }
}
}