def _generate_struct_serializer(self, struct):
struct_name = fmt_class_prefix(struct)<EOL>with self.block_func(<EOL>func='<STR_LIT>',<EOL>args=fmt_func_args_declaration([('<STR_LIT>',<EOL>'<STR_LIT>'.format(struct_name))]),<EOL>return_type='<STR_LIT>',<EOL>class_func=True):<EOL><INDENT>if not struct.all_fields and not struct.has_enumerated_subtypes():<EOL><INDENT>self.emit('<STR_LIT>')<EOL><DEDENT>self.emit(<EOL>'<STR_LIT>'<EOL>)<EOL>self.emit()<EOL>for field in struct.all_fields:<EOL><INDENT>data_type, nullable = unwrap_nullable(field.data_type)<EOL>input_value = '<STR_LIT>'.format(fmt_var(field.name))<EOL>serialize_call = self._fmt_serialization_call(<EOL>field.data_type, input_value, True)<EOL>if not nullable:<EOL><INDENT>if is_primitive_type(data_type):<EOL><INDENT>self.emit('<STR_LIT>'.format(<EOL>field.name, input_value))<EOL><DEDENT>else:<EOL><INDENT>self.emit('<STR_LIT>'.format(<EOL>field.name, serialize_call))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>with self.block('<STR_LIT>'.format(input_value)):<EOL><INDENT>self.emit('<STR_LIT>'.format(<EOL>field.name, serialize_call))<EOL><DEDENT><DEDENT><DEDENT>self.emit()<EOL>if struct.has_enumerated_subtypes():<EOL><INDENT>first_block = True<EOL>for tags, subtype in struct.get_all_subtypes_with_tags():<EOL><INDENT>assert len(tags) == <NUM_LIT:1>, tags<EOL>tag = tags[<NUM_LIT:0>]<EOL>base_condition = '<STR_LIT>'<EOL>with self.block(<EOL>base_condition.format('<STR_LIT>' if first_block else<EOL>'<STR_LIT>',<EOL>fmt_class_prefix(subtype))):<EOL><INDENT>if first_block:<EOL><INDENT>first_block = False<EOL><DEDENT>func_args = fmt_func_args([('<STR_LIT:value>',<EOL>'<STR_LIT>'.format(<EOL>fmt_class_prefix(<EOL>subtype)))])<EOL>caller = fmt_serial_class(fmt_class_prefix(subtype))<EOL>serialize_call = fmt_func_call(<EOL>caller=caller, callee='<STR_LIT>', args=func_args)<EOL>self.emit('<STR_LIT>'.format(<EOL>serialize_call))<EOL>with self.block(<EOL>'<STR_LIT>'):<EOL><INDENT>self.emit('<STR_LIT>')<EOL><DEDENT>self.emit(<EOL>'<STR_LIT>'.format(fmt_var(tag)))<EOL><DEDENT><DEDENT>self.emit()<EOL><DEDENT>self.emit('<STR_LIT>')<EOL><DEDENT>self.emit()<EOL>
Emits the serialize method for the serialization object for the given struct.