B2G/gecko/dom/system/gonk/RadioInterfaceLayer.js
/**
   * Calculate user data length of specified message string encoded in GSM 7Bit
   * alphabets.
   *
   * @param message
   *        a message string to be encoded.
   * @param strict7BitEncoding
   *        Optional. Enable Latin characters replacement with corresponding
   *        ones in GSM SMS 7-bit default alphabet.
   *
   * @return null or an options object with attributes `dcs`,
   *         `userDataHeaderLength`, `encodedFullBodyLength`, `langIndex`,
   *         `langShiftIndex`, `segmentMaxSeq` set.
   *
   * @see #_calculateUserDataLength().
   */
Calculate user data length of specified message string encoded in GSM 7Bit
alphabets.

@param message
a message string to be encoded.




Calculate user data length of specified message string encoded in GSM 7Bit alphabets . @param message a message string to be encoded .
function _calculateUserDataLength7Bit(message, strict7BitEncoding) {
    let options = null;
    let minUserDataSeptets = Number.MAX_VALUE;
    for (let i = 0; i < this.enabledGsmTableTuples.length; i++) {
      let [langIndex, langShiftIndex] = this.enabledGsmTableTuples[i];
      const langTable = RIL.PDU_NL_LOCKING_SHIFT_TABLES[langIndex];
      const langShiftTable = RIL.PDU_NL_SINGLE_SHIFT_TABLES[langShiftIndex];
      let bodySeptets = this._countGsm7BitSeptets(message,
                                                  langTable,
                                                  langShiftTable,
                                                  strict7BitEncoding);
      if (bodySeptets < 0) {
        continue;
      }
      let headerLen = 0;
      if (langIndex != RIL.PDU_NL_IDENTIFIER_DEFAULT) {
        headerLen += 3; 
      }
      if (langShiftIndex != RIL.PDU_NL_IDENTIFIER_DEFAULT) {
        headerLen += 3; 
      }
      let headerSeptets = Math.ceil((headerLen ? headerLen + 1 : 0) * 8 / 7);
      let segmentSeptets = RIL.PDU_MAX_USER_DATA_7BIT;
      if ((bodySeptets + headerSeptets) > segmentSeptets) {
        headerLen += this.segmentRef16Bit ? 6 : 5;
        headerSeptets = Math.ceil((headerLen + 1) * 8 / 7);
        segmentSeptets -= headerSeptets;
      }
      let segments = Math.ceil(bodySeptets / segmentSeptets);
      let userDataSeptets = bodySeptets + headerSeptets * segments;
      if (userDataSeptets >= minUserDataSeptets) {
        continue;
      }
      minUserDataSeptets = userDataSeptets;
      options = {
        dcs: RIL.PDU_DCS_MSG_CODING_7BITS_ALPHABET,
        encodedFullBodyLength: bodySeptets,
        userDataHeaderLength: headerLen,
        langIndex: langIndex,
        langShiftIndex: langShiftIndex,
        segmentMaxSeq: segments,
        segmentChars: segmentSeptets,
      };
    }
    return options;
  }
function _calculateUserDataLength7Bit ( message , strict7BitEncoding ) { let options = null ; let minUserDataSeptets = Number . MAX_VALUE ; for ( let i = 0 ; i < this . enabledGsmTableTuples . length ; i ++ ) { let [ langIndex , langShiftIndex ] = this . enabledGsmTableTuples [ i ] ; const langTable = RIL . PDU_NL_LOCKING_SHIFT_TABLES [ langIndex ] ; const langShiftTable = RIL . PDU_NL_SINGLE_SHIFT_TABLES [ langShiftIndex ] ; let bodySeptets = this . _countGsm7BitSeptets ( message , langTable , langShiftTable , strict7BitEncoding ) ; if ( bodySeptets < 0 ) { continue ; } let headerLen = 0 ; if ( langIndex != RIL . PDU_NL_IDENTIFIER_DEFAULT ) { headerLen += 3 ; } if ( langShiftIndex != RIL . PDU_NL_IDENTIFIER_DEFAULT ) { headerLen += 3 ; } let headerSeptets = Math . ceil ( ( headerLen ? headerLen + 1 : 0 ) * 8 / 7 ) ; let segmentSeptets = RIL . PDU_MAX_USER_DATA_7BIT ; if ( ( bodySeptets + headerSeptets ) > segmentSeptets ) { headerLen += this . segmentRef16Bit ? 6 : 5 ; headerSeptets = Math . ceil ( ( headerLen + 1 ) * 8 / 7 ) ; segmentSeptets -= headerSeptets ; } let segments = Math . ceil ( bodySeptets / segmentSeptets ) ; let userDataSeptets = bodySeptets + headerSeptets * segments ; if ( userDataSeptets >= minUserDataSeptets ) { continue ; } minUserDataSeptets = userDataSeptets ; options = { dcs : RIL . PDU_DCS_MSG_CODING_7BITS_ALPHABET , encodedFullBodyLength : bodySeptets , userDataHeaderLength : headerLen , langIndex : langIndex , langShiftIndex : langShiftIndex , segmentMaxSeq : segments , segmentChars : segmentSeptets , } ; } return options ; }
Calculate user data length of specified message string encoded in GSM 7Bit
 alphabets.
Calculate user data length of specified message string encoded in GSM 7Bit alphabets .
// IEI + len + langIndex // IEI + len + langShiftIndex // Calculate full user data length, note the extra byte is for header len