@@ -623,12 +623,21 @@ def presence_type(self):
623623 def _complex_member_type (self , ri ):
624624 if "type" not in self .attr or self .attr ["type" ] == "nest" :
625625 return self .nested_struct_type
626+ elif self .attr ["type" ] == "binary" and "struct" in self .attr :
627+ return None # use arg_member()
626628 elif self .attr ["type" ] in scalars :
627629 scalar_pfx = "__" if ri .ku_space == "user" else ""
628630 return scalar_pfx + self .attr ["type" ]
629631 else :
630632 raise Exception (f"Sub-type { self .attr ['type' ]} not supported yet" )
631633
634+ def arg_member (self , ri ):
635+ if self .attr ["type" ] == "binary" and "struct" in self .attr :
636+ return [
637+ f'std::vector<struct { c_lower (self .attr ["struct" ])} > { self .c_name } ' ,
638+ ]
639+ return super ().arg_member (ri )
640+
632641 def _attr_policy (self , policy ):
633642 return self .base_type ._attr_policy (policy )
634643
@@ -645,6 +654,11 @@ def attr_put(self, ri, var):
645654 ri .cw .p (
646655 f"ynl_attr_put_{ put_type } (nlh, { self .enum_name } , { var } .{ self .c_name } [i]);"
647656 )
657+ elif self .attr ["type" ] == "binary" and "struct" in self .attr :
658+ ri .cw .p (f"for (unsigned int i = 0; i < { var } .{ self .c_name } .size(); i++)" )
659+ ri .cw .p (
660+ f"ynl_attr_put(nlh, { self .enum_name } , &{ var } .{ self .c_name } [i], sizeof(struct { c_lower (self .attr ['struct' ])} ));"
661+ )
648662 elif "type" not in self .attr or self .attr ["type" ] == "nest" :
649663 ri .cw .p (f"for (unsigned int i = 0; i < { var } .{ self .c_name } .size(); i++)" )
650664 self ._attr_put_line (
@@ -1851,6 +1865,12 @@ def _multi_parse(ri, struct, init_lines, local_vars):
18511865 ri .cw .p ("return YNL_PARSE_CB_ERROR;" )
18521866 elif aspec .type in scalars :
18531867 ri .cw .p (f"dst->{ aspec .c_name } [i] = ynl_attr_get_{ aspec .type } (attr);" )
1868+ elif aspec .type == "binary" and "struct" in aspec :
1869+ ri .cw .p ("size_t len = ynl_attr_data_len(attr);" )
1870+ ri .cw .nl ()
1871+ ri .cw .p (f"if (len > sizeof(dst->{ aspec .c_name } [0]))" )
1872+ ri .cw .p (f"len = sizeof(dst->{ aspec .c_name } [0]);" )
1873+ ri .cw .p (f"memcpy(&dst->{ aspec .c_name } [i], ynl_attr_data(attr), len);" )
18541874 else :
18551875 raise Exception ("Nest parsing type not supported yet" )
18561876 ri .cw .p ("i++;" )
0 commit comments