nodes: 0, module; 1, function_definition; 2, function_name:_FlushExportBuffer; 3, parameters; 4, block; 5, identifier:self; 6, identifier:output_module; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, for_statement; 14, if_statement; 15, identifier:deduplicate_events; 16, True; 17, comment:"""Flushes buffered events and writes them to the output module.
  
      Args:
        output_module (OutputModule): output module.
        deduplicate_events (Optional[bool]): True if events should be
            deduplicated.
      """; 18, assignment; 19, assignment; 20, assignment; 21, assignment; 22, pattern_list; 23, identifier:generator; 24, block; 25, identifier:macb_group; 26, block; 27, identifier:last_macb_group_identifier; 28, None; 29, identifier:last_content_identifier; 30, None; 31, identifier:macb_group; 32, list; 33, identifier:generator; 34, call; 35, identifier:macb_group_identifier; 36, identifier:content_identifier; 37, identifier:event; 38, if_statement; 39, if_statement; 40, expression_statement; 41, expression_statement; 42, expression_statement; 43, attribute; 44, argument_list; 45, boolean_operator; 46, block; 47, comparison_operator:macb_group_identifier is None; 48, block; 49, else_clause; 50, assignment; 51, assignment; 52, call; 53, attribute; 54, identifier:PopEvents; 55, identifier:deduplicate_events; 56, comparison_operator:last_content_identifier == content_identifier; 57, expression_statement; 58, continue_statement; 59, identifier:macb_group_identifier; 60, None; 61, if_statement; 62, expression_statement; 63, block; 64, identifier:last_macb_group_identifier; 65, identifier:macb_group_identifier; 66, identifier:last_content_identifier; 67, identifier:content_identifier; 68, attribute; 69, argument_list; 70, identifier:self; 71, identifier:_export_event_heap; 72, identifier:last_content_identifier; 73, identifier:content_identifier; 74, augmented_assignment; 75, identifier:macb_group; 76, block; 77, call; 78, if_statement; 79, expression_statement; 80, identifier:output_module; 81, identifier:WriteEventMACBGroup; 82, identifier:macb_group; 83, attribute; 84, integer:1; 85, expression_statement; 86, expression_statement; 87, attribute; 88, argument_list; 89, parenthesized_expression; 90, block; 91, else_clause; 92, augmented_assignment; 93, attribute; 94, identifier:number_of_duplicate_events; 95, call; 96, assignment; 97, identifier:output_module; 98, identifier:WriteEvent; 99, identifier:event; 100, boolean_operator; 101, expression_statement; 102, block; 103, attribute; 104, integer:1; 105, identifier:self; 106, identifier:_events_status; 107, attribute; 108, argument_list; 109, identifier:macb_group; 110, list; 111, comparison_operator:last_macb_group_identifier == macb_group_identifier; 112, not_operator; 113, call; 114, expression_statement; 115, expression_statement; 116, attribute; 117, identifier:number_of_macb_grouped_events; 118, identifier:output_module; 119, identifier:WriteEventMACBGroup; 120, identifier:macb_group; 121, identifier:last_macb_group_identifier; 122, identifier:macb_group_identifier; 123, identifier:macb_group; 124, attribute; 125, argument_list; 126, call; 127, assignment; 128, identifier:self; 129, identifier:_events_status; 130, identifier:macb_group; 131, identifier:append; 132, identifier:event; 133, attribute; 134, argument_list; 135, identifier:macb_group; 136, list; 137, identifier:output_module; 138, identifier:WriteEventMACBGroup; 139, identifier:macb_group; 140, identifier:event
code: def _FlushExportBuffer(self, output_module, deduplicate_events=True):
      """Flushes buffered events and writes them to the output module.
  
      Args:
        output_module (OutputModule): output module.
        deduplicate_events (Optional[bool]): True if events should be
            deduplicated.
      """
      last_macb_group_identifier = None
      last_content_identifier = None
      macb_group = []
  
      generator = self._export_event_heap.PopEvents()
  
      for macb_group_identifier, content_identifier, event in generator:
        if deduplicate_events and last_content_identifier == content_identifier:
          self._events_status.number_of_duplicate_events += 1
          continue
  
        if macb_group_identifier is None:
          if macb_group:
            output_module.WriteEventMACBGroup(macb_group)
            macb_group = []
  
          output_module.WriteEvent(event)
  
        else:
          if (last_macb_group_identifier == macb_group_identifier or
              not macb_group):
            macb_group.append(event)
  
          else:
            output_module.WriteEventMACBGroup(macb_group)
            macb_group = [event]
  
          self._events_status.number_of_macb_grouped_events += 1
  
        last_macb_group_identifier = macb_group_identifier
        last_content_identifier = content_identifier
  
      if macb_group:
        output_module.WriteEventMACBGroup(macb_group)