def unpack(cls, data): length, type = cls.rtattr.unpack(data[:cls.rtattr.size]) data_len = length - cls.rtattr.size attr_data = struct.unpack( '{0}s'.format(data_len), data[cls.rtattr.size:cls.rtattr.size + data_len])[0] return cls(type, attr_data), data[align(length):]
def __len__(self): """Aligned length of service template message + attributes.""" return align(self.nlmsghdr.size + len(self.payload))
def __repr__(self): return """<rtattr datalen=%d rta_type=%d data="%s">""" % ( align(len(self.payload)), self.rta_type, self.payload.encode('string_escape'))
def pack(self): data = struct.pack('{0}s'.format(len(self.payload)), self.payload) rta_len = self.rtattr.size+len(data) return struct.pack('{0}{1}s'.format(self.rtattr.format, align(len(data))), rta_len, self.rta_type, data)
def unpack(cls, data): length, type = cls.rtattr.unpack(data[:cls.rtattr.size]) data_len = length-cls.rtattr.size attr_data = struct.unpack('{0}s'.format(data_len), data[cls.rtattr.size:cls.rtattr.size+data_len])[0] return cls(type, attr_data), data[align(length):]
def pack(self): data = struct.pack('{0}s'.format(len(self.payload)), self.payload) rta_len = self.rtattr.size + len(data) return struct.pack( '{0}{1}s'.format(self.rtattr.format, align(len(data))), rta_len, self.rta_type, data)