···218218 description: Max length for a string or a binary attribute.219219 $ref: '#/$defs/len-or-define'220220 sub-type: *attr-type221221+ # Start genetlink-legacy222222+ struct:223223+ description: Name of the struct type used for the attribute.224224+ type: string225225+ # End genetlink-legacy221226222227 # Make sure name-prefix does not appear in subsets (subsets inherit naming)223228 dependencies:
+2
tools/net/ynl/lib/nlspec.py
···152152 value numerical ID when serialized153153 attr_set Attribute Set containing this attr154154 is_multi bool, attr may repeat multiple times155155+ struct_name string, name of struct definition155156 sub_type string, name of sub type156157 """157158 def __init__(self, family, attr_set, yaml, value):···161160 self.value = value162161 self.attr_set = attr_set163162 self.is_multi = yaml.get('multi-attr', False)163163+ self.struct_name = yaml.get('struct')164164 self.sub_type = yaml.get('sub-type')165165166166
+14-1
tools/net/ynl/lib/ynl.py
···102102 format, _ = self.type_formats[type]103103 return list({ x[0] for x in struct.iter_unpack(format, self.raw) })104104105105+ def as_struct(self, members):106106+ value = dict()107107+ offset = 0108108+ for m in members:109109+ # TODO: handle non-scalar members110110+ format, size = self.type_formats[m.type]111111+ decoded = struct.unpack_from(format, self.raw, offset)112112+ offset += size113113+ value[m.name] = decoded[0]114114+ return value115115+105116 def __repr__(self):106117 return f"[type:{self.type} len:{self._len}] {self.raw}"107118···388377 rsp[attr_spec['name']] = value389378390379 def _decode_binary(self, attr, attr_spec):391391- if attr_spec.sub_type:380380+ if attr_spec.struct_name:381381+ decoded = attr.as_struct(self.consts[attr_spec.struct_name])382382+ elif attr_spec.sub_type:392383 decoded = attr.as_c_array(attr_spec.sub_type)393384 else:394385 decoded = attr.as_bin()