docs: def rs_correct_msg(msg_in, nsym, fcr=0, generator=2, erase_pos=None, only_erasures=False):
      '''Reed-Solomon main decoding function'''
      global field_charac
      if len(msg_in) > field_charac:
          # Note that it is in fact possible to encode/decode messages that are longer than field_charac, but because this will be above the field, this will generate more error positions during Chien Search than it should, because this will generate duplicate values, which should normally be prevented thank's to the prime polynomial reduction (eg, because it can't discriminate between error at position 1 or 256, both being exactly equal under galois field 2^8). So it's really not advised to do it, but it's possible (but then you're not guaranted to be able to correct any error/erasure on symbols with a position above the length of field_charac -- if you really need a bigger message without chunking, then you should better enlarge c_exp so that you get a bigger field).
          raise ValueError("Message is too long (%i when max is %i)" % (len(msg_in), field_charac))
  
      msg_out = bytearray(msg_in)     # copy of message
      # erasures: set them to null bytes for easier decoding (but this is not necessary, they will be corrected anyway, but debugging will be easier with null bytes because the error locator polynomial values will only depend on the errors locations, not their values)
      if erase_pos is None:
          erase_pos = []
      else:
          for e_pos in erase_pos:
              msg_out[e_pos] = 0
      # check if there are too many erasures to correct (beyond the Singleton bound)
      if len(erase_pos) > nsym: raise ReedSolomonError("Too many erasures to correct")
      # prepare the syndrome polynomial using only errors (ie: errors = characters that were either replaced by null byte or changed to another character, but we don't know their positions)
      synd = rs_calc_syndromes(msg_out, nsym, fcr, generator)
      # check if there's any error/erasure in the input codeword. If not (all syndromes coefficients are 0), then just return the codeword as-is.
      if max(synd) == 0:
          return msg_out[:-nsym], msg_out[-nsym:]  # no errors
      
      # Find errors locations
      if only_erasures:
          err_pos = []
      else:
          # compute the Forney syndromes, which hide the erasures from the original syndrome (so that BM will just have to deal with errors, not erasures)
          fsynd = rs_forney_syndromes(synd, erase_pos, len(msg_out), generator)
          # compute the error locator polynomial using Berlekamp-Massey
          err_loc = rs_find_error_locator(fsynd, nsym, erase_count=len(erase_pos))
          # locate the message errors using Chien search (or bruteforce search)
          err_pos = rs_find_errors(err_loc[::-1], len(msg_out), generator)
          if err_pos is None:
              raise ReedSolomonError("Could not locate error")
  
      # Find errors values and apply them to correct the message
      # compute errata evaluator and errata magnitude polynomials, then correct errors and erasures
      msg_out = rs_correct_errata(msg_out, synd, (erase_pos + err_pos), fcr, generator) # note that we here use the original syndrome, not the forney syndrome (because we will correct both errors and erasures, so we need the full syndrome)
      # check if the final message is fully repaired
      synd = rs_calc_syndromes(msg_out, nsym, fcr, generator)
      if max(synd) > 0:
          raise ReedSolomonError("Could not correct message")
      # return the successfully decoded message
      return msg_out[:-nsym], msg_out[-nsym:]