+ def print_array(self, o, stream):
+ write = stream.write
+
+ forloop = '''\
+ for (i = 0; i < {lfield}; i++) {{
+ s = format(s, "\\n%U{n}: %U",
+ format_white_space, indent, format_{t}, &a->{n}[i], indent);
+ }}
+'''
+
+ forloop_format = '''\
+ for (i = 0; i < {lfield}; i++) {{
+ s = format(s, "\\n%U{n}: {t}",
+ format_white_space, indent, a->{n}[i]);
+ }}
+'''
+
+ if o.fieldtype == 'string':
+ return self.print_string(o, stream)
+
+ if o.fieldtype == 'u8':
+ if o.lengthfield:
+ write(' s = format(s, "\\n%U{n}: %U", format_white_space, '
+ 'indent, format_hex_bytes, a->{n}, a->{lfield});\n'
+ .format(n=o.fieldname, lfield=o.lengthfield))
+ else:
+ write(' s = format(s, "\\n%U{n}: %U", format_white_space, '
+ 'indent, format_hex_bytes, a, {lfield});\n'
+ .format(n=o.fieldname, lfield=o.length))
+ return
+
+ lfield = 'a->' + o.lengthfield if o.lengthfield else o.length
+ if o.fieldtype in format_strings:
+ write(forloop_format.format(lfield=lfield,
+ t=format_strings[o.fieldtype],
+ n=o.fieldname))
+ else:
+ write(forloop.format(lfield=lfield, t=o.fieldtype, n=o.fieldname))
+
+ _dispatch['Array'] = print_array
+
+ def print_alias(self, k, v, stream):
+ write = stream.write
+ if ('length' in v.alias and v.alias['length'] and
+ v.alias['type'] == 'u8'):
+ write(' return format(s, "%U", format_hex_bytes, a, {});\n'
+ .format(v.alias['length']))
+ elif v.alias['type'] in format_strings:
+ write(' return format(s, "{}", *a);\n'
+ .format(format_strings[v.alias['type']]))
+ else:
+ write(' return format(s, "{} (print not implemented)"'
+ .format(k))
+
+ def print_enum(self, o, stream):
+ write = stream.write
+ write(" switch(*a) {\n")
+ for b in o:
+ write(" case %s:\n" % b[1])
+ write(' return format(s, "{}");\n'.format(b[0]))
+ write(' }\n')
+
+ _dispatch['Enum'] = print_enum
+
+ def print_obj(self, o, stream):
+ write = stream.write
+
+ if o.type in self._dispatch:
+ self._dispatch[o.type](self, o, stream)
+ else:
+ write(' s = format(s, "\\n{} {} {} (print not implemented");\n'
+ .format(o.type, o.fieldtype, o.fieldname))
+
+
+def printfun(objs, stream, modulename):
+ write = stream.write
+
+ h = '''\