from pprint import pprint
from pyroute2.netlink.rtnl.tcmsg import tcmsg
import io
import sys


f = open(sys.argv[1], 'r')
b = io.BytesIO()

for a in f.readlines():
    if a[0] == '#':
        continue
    while True:
        try:
            b.write(chr(int(a[2:4], 16)))
        except:
            break
        a = a[4:]

b.seek(0)
t = tcmsg(b)
t.decode()
pprint(t)

@@ -1,98 +1,397 @@
-from pprint import pprint%0Afrom pyroute2.netlink.rtnl.tcmsg import tcmsg%0Aimport io%0Aimport sys%0A%0A
+#!/usr/bin/python%0A'''%0AUsage::%0A%0A    ./decoder.py %5Bmodule%5D %5Bdata_file%5D%0A%0ASample::%0A%0A    ./decoder.py tcmsg ./sample_packet_01.data%0A%0AModule is a name within rtnl hierarchy. File should be a%0Abinary data in the escaped string format (see samples).%0A'''%0Aimport io%0Aimport sys%0Afrom pprint import pprint%0Afrom importlib import import_module%0A%0Atemplate = 'pyroute2.netlink.rtnl.%7Bmod%7D.%7Bmod%7D'%0Amod = sys.argv%5B1%5D
 %0Af =
@@ -405,17 +405,17 @@
 ys.argv%5B
-1
+2
 %5D, 'r')%0A
@@ -431,16 +431,151 @@
 tesIO()%0A
+s = template.format(mod=mod).split('.')%0Apackage = '.'.join(s%5B:-1%5D)%0Amodule = s%5B-1%5D%0Am = import_module(package)%0Amet = getattr(m, module)%0A%0A
 %0Afor a i
@@ -766,21 +766,19 @@
 (0)%0At = 
-tcmsg
+met
 (b)%0At.de

make the decoder script more flexible