-def _c_serialize_helper_prefix(prefix):
- # prefix is a list of (field_name, anchestor object) tuples
- # concatenate field names
- prefix_str = ''
- for name, obj in prefix:
- prefix_str += name
- prefix_str += '.' if (obj.is_bitcase and obj.has_name) else '->'
- lenfield_prefix = '' if prefix_str.find('_aux')==0 else "_aux"
- if prefix_str != '':
- if lenfield_prefix != '':
- lenfield_prefix += '->'
- lenfield_prefix += prefix_str
- return (prefix_str, lenfield_prefix)
-# _c_serialize_helper_prefix
-
-def _c_field_mapping(context, complex_type, prefix):
- def get_prefix(field, prefix):
- prefix_str, lenfield_prefix = _c_serialize_helper_prefix(prefix)
- if prefix_str == '':
- if context in ('serialize', 'unserialize'):
- if field.type.fixed_size() or complex_type.is_switch:
- prefix_str = '_aux->'
- else:
- raise Exception("unknown context '%s' in c_field_mapping" % context)
- return prefix_str
- # get_prefix()
- def get_field_name(fields, complex_type, prefix):
- for f in complex_type.fields:
- prefix_str = get_prefix(f, prefix)
-
- fname = "%s%s" % (prefix_str, f.c_field_name)
- if fields.has_key(f.field_name):
- continue
- # FIXME
- raise Exception("field name %s has been registered before" % f.field_name)
- fields[f.field_name] = (fname, f)
- if f.type.is_container:
- get_field_name(fields, f.type, prefix+[(f.c_field_name, f.type)])
- # get_field_name()
-
- # dict(field_name : (c_field_name, field))
- fields = {}
- get_field_name(fields, complex_type, prefix)
-
- # switch: get the fields referenced by the switch expr as well
- # these may not belong to any structure
- if complex_type.is_switch:
- pass
-# FIXME: fields += get_serialize_params(context, complex_type)
-
- return fields
-# _c_field_mapping()
-
-def _c_serialize_helper_insert_padding(context, code_lines, space):
- code_lines.append('%s xcb_buffer_len += xcb_block_len;' % space)
- code_lines.append('%s /* padding */' % space)