# Path: shapy/framework/netlink/message.py
# class ServiceTemplate(InterpreterMixin):
#     """Represents the second part of the Netlink message."""
#     @classmethod
#     def unpack(cls, data):
#         rest = data[cls.format.size:]
#         st_instance = cls(*cls.format.unpack(data[:cls.format.size]))
#         st_instance.attributes = tuple(st_instance.unpack_attrs(rest))
#         return st_instance
#     
#     def pack(self):
#         return ''
#     
#     def pack_attrs(self):
#         return ''.join(( a.pack() for a in self.attributes ))
#     
#     def unpack_attrs(self, data):
#         while True:
#             attr, data = Attr.unpack(data)
#             attr.service_template = self
#             yield attr
#             if not data: break


from struct import Struct
from .message import ServiceTemplate
from .constants import *
    #struct tcmsg {
    #    unsigned char    tcm_family;
    #    int              tcm_ifindex;   /* interface index */
    #    __u32            tcm_handle;    /* Qdisc handle */
    #    __u32            tcm_parent;    /* Parent qdisc */
    #    __u32            tcm_info;
    #};
    
    format = Struct("BxxxiIII")

    def __init__(self, tcm_family, tcm_ifindex, tcm_handle, tcm_parent, tcm_info,
                 attributes=[]):
        self.tcm_family = tcm_family
        self.tcm_ifindex = tcm_ifindex
        self.tcm_handle = tcm_handle
        self.tcm_parent = tcm_parent
        self.tcm_info = tcm_info
        self.attributes = attributes
    
    def pack(self):
        tm = tcmsg.format.pack(self.tcm_family, self.tcm_ifindex,
                               self.tcm_handle, self.tcm_parent, self.tcm_info)
        return tm + self.pack_attrs()

    def __repr__(self):
        return "<tcmsg family={0} if={1} handle={2:#x} parent={3:#x} info={4:#x}>".format(
            self.tcm_family, self.tcm_ifindex, self.tcm_handle,
            self.tcm_parent, self.tcm_info)



# Path: shapy/framework/netlink/message.py
# class ServiceTemplate(InterpreterMixin):
#     """Represents the second part of the Netlink message."""
#     @classmethod
#     def unpack(cls, data):
#         rest = data[cls.format.size:]
#         st_instance = cls(*cls.format.unpack(data[:cls.format.size]))
#         st_instance.attributes = tuple(st_instance.unpack_attrs(rest))
#         return st_instance
#     
#     def pack(self):
#         return ''
#     
#     def pack_attrs(self):
#         return ''.join(( a.pack() for a in self.attributes ))
#     
#     def unpack_attrs(self, data):
#         while True:
#             attr, data = Attr.unpack(data)
#             attr.service_template = self
#             yield attr
#             if not data: break


# Path: shapy/framework/netlink/tc.py
from struct import Struct
from .message import ServiceTemplate
from .constants import *

    #struct tcmsg {
    #    unsigned char    tcm_family;
    #    int              tcm_ifindex;   /* interface index */
    #    __u32            tcm_handle;    /* Qdisc handle */
    #    __u32            tcm_parent;    /* Parent qdisc */
    #    __u32            tcm_info;
    #};
    
    format = Struct("BxxxiIII")

    def __init__(self, tcm_family, tcm_ifindex, tcm_handle, tcm_parent, tcm_info,
                 attributes=[]):
        self.tcm_family = tcm_family
        self.tcm_ifindex = tcm_ifindex
        self.tcm_handle = tcm_handle
        self.tcm_parent = tcm_parent
        self.tcm_info = tcm_info
        self.attributes = attributes
    
    def pack(self):
        tm = tcmsg.format.pack(self.tcm_family, self.tcm_ifindex,
                               self.tcm_handle, self.tcm_parent, self.tcm_info)
        return tm + self.pack_attrs()

    def __repr__(self):
        return "<tcmsg family={0} if={1} handle={2:#x} parent={3:#x} info={4:#x}>".format(
            self.tcm_family, self.tcm_ifindex, self.tcm_handle,
            self.tcm_parent, self.tcm_info)



ServiceTemplate.register(tcmsg, (RTM_NEWQDISC, RTM_DELQDISC, RTM_GETQDISC,