docs: static String encodeHighLevel(String msg, Compaction compaction, Charset encoding) throws WriterException {
  
      //the codewords 0..928 are encoded as Unicode characters
      StringBuilder sb = new StringBuilder(msg.length());
  
      if (encoding == null) {
        encoding = DEFAULT_ENCODING;
      } else if (!DEFAULT_ENCODING.equals(encoding)) {
        CharacterSetECI eci = CharacterSetECI.getCharacterSetECIByName(encoding.name());
        if (eci != null) {
          encodingECI(eci.getValue(), sb);
        }
      }
  
      int len = msg.length();
      int p = 0;
      int textSubMode = SUBMODE_ALPHA;
  
      // User selected encoding mode
      switch (compaction) {
        case TEXT:
          encodeText(msg, p, len, sb, textSubMode);
          break;
        case BYTE:
          byte[] msgBytes = msg.getBytes(encoding);
          encodeBinary(msgBytes, p, msgBytes.length, BYTE_COMPACTION, sb);
          break;
        case NUMERIC:
          sb.append((char) LATCH_TO_NUMERIC);
          encodeNumeric(msg, p, len, sb);
          break;
        default:
          int encodingMode = TEXT_COMPACTION; //Default mode, see 4.4.2.1
          while (p < len) {
            int n = determineConsecutiveDigitCount(msg, p);
            if (n >= 13) {
              sb.append((char) LATCH_TO_NUMERIC);
              encodingMode = NUMERIC_COMPACTION;
              textSubMode = SUBMODE_ALPHA; //Reset after latch
              encodeNumeric(msg, p, n, sb);
              p += n;
            } else {
              int t = determineConsecutiveTextCount(msg, p);
              if (t >= 5 || n == len) {
                if (encodingMode != TEXT_COMPACTION) {
                  sb.append((char) LATCH_TO_TEXT);
                  encodingMode = TEXT_COMPACTION;
                  textSubMode = SUBMODE_ALPHA; //start with submode alpha after latch
                }
                textSubMode = encodeText(msg, p, t, sb, textSubMode);
                p += t;
              } else {
                int b = determineConsecutiveBinaryCount(msg, p, encoding);
                if (b == 0) {
                  b = 1;
                }
                byte[] bytes = msg.substring(p, p + b).getBytes(encoding);
                if (bytes.length == 1 && encodingMode == TEXT_COMPACTION) {
                  //Switch for one byte (instead of latch)
                  encodeBinary(bytes, 0, 1, TEXT_COMPACTION, sb);
                } else {
                  //Mode latch performed by encodeBinary()
                  encodeBinary(bytes, 0, bytes.length, encodingMode, sb);
                  encodingMode = BYTE_COMPACTION;
                  textSubMode = SUBMODE_ALPHA; //Reset after latch
                }
                p += b;
              }
            }
          }
          break;
      }
  
      return sb.toString();
    }