+def _c_sizeof_helper(self):
+ _h_setlevel(1)
+ _c_setlevel(1)
+
+ # _unserialize()
+ _hc('')
+ # _unserialize() returns the buffer size as well
+ _hc('int')
+
+ variable_size_fields = 0
+ # maximum space required for type definition of function arguments
+ maxtypelen = 0
+ param_fields, wire_fields, params = get_serialize_params('sizeof', self)
+
+ # determine N(variable_fields)
+ for field in param_fields:
+ # if self.is_switch, treat all fields as if they are variable sized
+ if not field.type.fixed_size() or self.is_switch:
+ variable_size_fields += 1
+ # determine maxtypelen
+ for p in params:
+ maxtypelen = max(maxtypelen, len(p[0]) + len(p[1]))
+
+ # write to .c/.h
+ for idx, p in enumerate(params):
+ line = ""
+ typespec, pointerspec, field_name = p
+ indent = ' '*(len(self.c_sizeof_name)+2)
+ # p==0: function declaration
+ if 0==idx:
+ line = "%s (" % self.c_sizeof_name
+ indent = ''
+ spacing = ' '*(maxtypelen-len(typespec)-len(pointerspec))
+ line += "%s%s%s %s%s /**< */" % (indent, typespec, spacing, pointerspec, field_name)
+ if idx < len(params)-1:
+ _hc("%s," % line)
+ else:
+ _h("%s);" % line)
+ _c("%s)" % line)
+
+ _c('{')
+ # if self.is_switch: call serialize
+ if self.is_switch:
+ _c(' %s _aux;', self.c_type)
+ param_names = [p[2] for p in params]
+ _c(' return %s(%s, &_aux);', self.c_unserialize_name, reduce(lambda x,y: "%s, %s" % (x, y), param_names))
+ # otherwise: evaluate parameters directly
+ else:
+ _c(' char *xcb_tmp = (char *)_buffer;')
+ if not self.var_followed_by_fixed_fields:
+ _c(' const %s *_aux = (%s *)_buffer;', self.c_type, self.c_type)
+ else:
+ _c(' %s *_aux = malloc(sizeof(%s));', self.c_type, self.c_type)
+ _c(' unsigned int xcb_buffer_len = 0;')
+ _c(' unsigned int xcb_block_len = 0;')
+ _c(' unsigned int xcb_pad = 0;')
+ code_lines = []
+ temp_vars = []
+ _c_serialize_helper('sizeof', self,
+ code_lines, temp_vars)
+ for t in temp_vars:
+ _c(t)
+ _c('')
+
+ for l in code_lines:
+ _c(l)
+ _c('')
+ if not self.is_switch:
+ if self.var_followed_by_fixed_fields:
+ _c(' free(_aux);')
+ _c(' return xcb_buffer_len;')
+
+ _c('}')
+# _c_sizeof_helper()
+