B2G/gecko/dom/mobilemessage/src/ril/MmsPduHelper.jsm
/**
   * @param data
   *        A wrapped object to store encoded raw data.
   * @param value
   *        An object of two string-typed attributes: address and type.
   */
@param data
A wrapped object to store encoded raw data.
@param value
An object of two string-typed attributes: address and type.
@param data A wrapped object to store encoded raw data . @param value An object of two string - typed attributes : address and type .
function encode(data, value) {
    if (!value || !value.type || !value.address) {
      throw new WSP.CodeError("Address: invalid value");
    }
    let str;
    switch (value.type) {
      case "email":
        if (value.address.indexOf("@") > 0) {
          str = value.address;
        }
        break;
      case "num":
        if (value.address.match(this.REGEXP_NUM)) {
          str = value.address;
        }
        break;
      case "alphanum":
        if (value.address.match(this.REGEXP_ALPHANUM)) {
          str = value.address;
        }
        break;
      case "IPv4":
        if (value.address.match(this.REGEXP_ENCODE_IPV4)) {
          str = value.address + "/TYPE=IPv4";
        }
        break;
      case "IPv6":
        if (value.address.match(this.REGEXP_ENCODE_IPV6)) {
          str = value.address + "/TYPE=IPv6";
        }
        break;
      case "PLMN":
        if (value.address.match(this.REGEXP_ENCODE_PLMN)) {
          str = value.address + "/TYPE=PLMN";
        }
        break;
      default:
        if (value.type.match(this.REGEXP_ENCODE_CUSTOM_TYPE)
            && value.address.match(this.REGEXP_ENCODE_CUSTOM_ADDR)) {
          str = value.address + "/TYPE=" + value.type;
	}
        break;
    }
    if (!str) {
      throw new WSP.CodeError("Address: invalid value: " + JSON.stringify(value));
    }
    EncodedStringValue.encode(data, str);
  }
function encode ( data , value ) { if ( ! value || ! value . type || ! value . address ) { throw new WSP . CodeError ( "Address: invalid value" ) ; } let str ; switch ( value . type ) { case "email" : if ( value . address . indexOf ( "@" ) > 0 ) { str = value . address ; } break ; case "num" : if ( value . address . match ( this . REGEXP_NUM ) ) { str = value . address ; } break ; case "alphanum" : if ( value . address . match ( this . REGEXP_ALPHANUM ) ) { str = value . address ; } break ; case "IPv4" : if ( value . address . match ( this . REGEXP_ENCODE_IPV4 ) ) { str = value . address + "/TYPE=IPv4" ; } break ; case "IPv6" : if ( value . address . match ( this . REGEXP_ENCODE_IPV6 ) ) { str = value . address + "/TYPE=IPv6" ; } break ; case "PLMN" : if ( value . address . match ( this . REGEXP_ENCODE_PLMN ) ) { str = value . address + "/TYPE=PLMN" ; } break ; default : if ( value . type . match ( this . REGEXP_ENCODE_CUSTOM_TYPE ) && value . address . match ( this . REGEXP_ENCODE_CUSTOM_ADDR ) ) { str = value . address + "/TYPE=" + value . type ; } break ; } if ( ! str ) { throw new WSP . CodeError ( "Address: invalid value: " + JSON . stringify ( value ) ) ; } EncodedStringValue . encode ( data , str ) ; }
@param data
        A wrapped object to store encoded raw data.
@param data A wrapped object to store encoded raw data .