code: def calc_core_bytes(self):
          
          # The difference sample to write
          if len(self.sample) == 1:
              sampdiff = np.array([self.sample[0]])
          else:
              sampdiff = np.concatenate(([self.sample[0]], np.diff(self.sample)))
  
          # Create a copy of the annotation object with a
          # compact version of fields to write
          compact_annotation = copy.deepcopy(self)
          compact_annotation.compact_fields()
  
  
          # The optional fields to be written. Write if they are not None or all empty
          extra_write_fields = []
  
          for field in ['num', 'subtype', 'chan', 'aux_note']:
              if not isblank(getattr(compact_annotation, field)):
                  extra_write_fields.append(field)
  
          data_bytes = []
  
          # Iterate across all fields one index at a time
          for i in range(len(sampdiff)):
  
              # Process the samp (difference) and sym items
              data_bytes.append(field2bytes('samptype', [sampdiff[i], self.symbol[i]]))
  
              # Process the extra optional fields
              for field in extra_write_fields:
                  value = getattr(compact_annotation, field)[i]
                  if value is not None:
                      data_bytes.append(field2bytes(field, value))
  
          # Flatten and convert to correct format
          data_bytes = np.array([item for sublist in data_bytes for item in sublist]).astype('u1')
  
          return data_bytes
docs: Convert all used annotation fields into bytes to write