2023-11-15 12:56:37 +00:00
|
|
|
from yangson import DataModel
|
|
|
|
|
|
|
|
import cbor
|
|
|
|
import json
|
|
|
|
|
2023-11-23 08:23:46 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2023-11-15 12:56:37 +00:00
|
|
|
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)
|
2023-11-23 08:23:46 +00:00
|
|
|
|
|
|
|
cwd = os.getcwd()
|
|
|
|
os.chdir(os.path.dirname(sys.modules[__name__].__file__))
|
2023-11-15 12:56:37 +00:00
|
|
|
self.dm = DataModel.from_file('yang-library.json')
|
2023-11-23 08:23:46 +00:00
|
|
|
os.chdir(cwd)
|
2023-11-15 12:56:37 +00:00
|
|
|
self.data = self.dm.from_raw(self.raw)
|
|
|
|
self.data.validate()
|