- for field in self.fields:
- value = None
-
- # sort out invisible fields
- if not ((field.wire and not field.auto) or field.visible):
- continue
-
- length = "sizeof(%s)" % field.c_field_type
-
- # switch/bitcase: fixed size fields are serialized explicitly
- if field.type.fixed_size() and bitcase:
- value = ' xcb_parts[xcb_parts_idx].iov_base = (char *) '
- need_padding = True
-
- if field.type.is_expr:
- # need to register a temporary variable for the expression
- if field.type.c_type is None:
- raise Exception("type for field '%s' (expression '%s') unkown" %
- (field.field_name, _c_accessor_get_expr(field.type.expr)))
- temp_vars.add(' %s xcb_expr_%s = %s;' % (field.type.c_type, field.field_name,
- _c_accessor_get_expr(field.type.expr, prefix)))
- value += "&xcb_expr_%s;" % field.field_name
-
- elif field.type.is_pad:
- if field.type.nmemb == 1:
- value += "&xcb_pad;"
- else:
- value = ' memset(xcb_parts[xcb_parts_idx].iov_base, 0, %d);' % field.type.nmemb
- length += "*%d" % field.type.nmemb
-
- else:
- # non-list type with fixed size
- if field.type.nmemb == 1:
- value += "&%s%s;" % (prefix_str, field.c_field_name)
- # list with nmemb (fixed size) elements
- else:
- value += '%s%s;' % (prefix_str, field.c_field_name)
- length = '%d' % field.type.nmemb
-
- # fields with variable size
- elif not field.type.fixed_size():
- # calculate padding before variable sized fields only if necessary
- if bitcase or need_padding:
- count = insert_padding(count)
- code_lines.append('%s xcb_block_len = 0;' % space)
- need_padding = False
-
- code_lines.append('%s /* %s */' % (space, field.c_field_name))
- value = ' xcb_parts[xcb_parts_idx].iov_base = (char *) %s%s;' % (prefix_str, field.c_field_name)
- length = ''
- code_lines.append('%s%s' % (space, value))
-
- if field.type.is_list:
- # list of variable length with variable size elements
- if field.type.size is None:
- errmsg = '%s: warning: list object with variable-sized members not supported for field %s\n'
- sys.stderr.write(errmsg % (self.c_type, field.c_field_name))
- code_lines.append('%s xcb_parts[xcb_parts_idx].iov_len = 0;' % space)
- code_lines.append('%s xcb_tmp = (char *) %s%s;' % (space, prefix_str, field.c_field_name))
- code_lines.append('%s for(i=0; i<%s; i++) {'
- % (space, _c_accessor_get_expr(field.type.expr, lenfield_prefix)))
- code_lines.append('%s xcb_block_len = %s(xcb_tmp);' % (space, field.type.c_unserialize_name))
- code_lines.append('%s xcb_parts[xcb_parts_idx].iov_len += xcb_block_len;' % space)
- code_lines.append('%s xcb_tmp += xcb_block_len;' % space)
- code_lines.append('%s }' % space)
- code_lines.append('%s xcb_block_len = xcb_parts[xcb_parts_idx].iov_len;' % space)
-
- # list of variable length with fixed size elements
- else:
- # look if the list's lenfield is a struct member or a function argument
- lf_prefix = lenfield_prefix
- # special case: if the list has a length field, its name will returned
- # unchanged by calling c_accessor_get_length(expr)
- expr = field.type.expr
- if expr.lenfield_name == _c_accessor_get_length(expr):
- if expr.lenfield_name in param_names:
- # the length field appears as separate argument in unserialize,
- # so no need for a prefix
- lf_prefix = ''
-
- length = '%s * sizeof(%s)' % (_c_accessor_get_expr(field.type.expr, lf_prefix),
- field.type.member.c_wiretype)
-
- elif field.type.is_switch:
- # switch is handled at the beginning of this function as a special case
-# count += serialize_fields(field.type, code_lines, temp_vars, space,
- # prefix="%s%s" % (prefix_str, field.c_field_name))
- # FIXME - call another serialize
- value = ''
- sys.stderr.write("FIXME: call %s" % field.type.c_serialize_name)
- length = 'undefined'
- else:
- # FIXME - variable sized field that is not a list
- errmsg = '%s: warning: non-list object of variable size not supported for field %s\n'
- sys.stderr.write(errmsg % (self.c_type, field.c_field_name))
- length = '%s * sizeof(%s)' % ('undefined', field.type.c_wiretype)
-
- # save serialization C code using xcb_parts[].iov_base and xcb_parts[].iov_len
- if value is not None:
- if field.type.fixed_size():
- # field belongs to some anchestor structure
- code_lines.append('%s /* %s.%s */' % (space, self.c_type, field.c_field_name))
- code_lines.append('%s%s' % (space, value))
- if bitcase:
- code_lines.append('%s xcb_block_len += %s;' % (space, length))
- if length != '':
- if not field.type.fixed_size():
- code_lines.append('%s xcb_block_len = %s;' % (space, length))
- code_lines.append('%s xcb_parts[xcb_parts_idx].iov_len = xcb_block_len;' % space)
- # increase xcb_parts index
- code_lines.append('%s xcb_parts_idx++;' % space)
- count += 1
-
- if not field.type.fixed_size():
- # FIXME
- count = insert_padding(count)
- need_padding = False
- # raise Exception("obsolete - should not be reached")
- # code_lines.append('%s xcb_unpadded = xcb_parts[xcb_parts_idx].iov_len;' % space)
-
- return count
-# serialize_fields()
-
-def _c_serialize(self):