Encode a text message body
173112
private void encodeTextBody(StringBuffer result, JsJmsTextMessage msg) {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(tc, "encodeTextBody");
    try {
      String body = msg.getText();
      if (body != null) {
        result.append('~');
        URLEncode(result, body);
      }
    }
    catch (UnsupportedEncodingException e) {
      FFDCFilter.processException(e, "com.ibm.ws.sib.mfp.impl.WebJsJmsMessageEncoderImpl.encodeTextBody", "193");
      // Just treat it as null.
    }
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(tc, "encodeTextBody");
  }
1104210
private static function bodyToText(\Google_Service_Gmail_MessagePartBody $body = null): string
    {
        $sanitizedData = strtr($body->getData(), '-_', '+/');

        // On fail base64_decode returns false.
        // We can't know with certainty that getData() is ok.
        // So fail gracefully.
        return base64_decode($sanitizedData) ?? '';
    }
1187658
def encode_params(self, data=None, **kwargs):
        
        if isinstance(data, basestring):
            raise ValueError("Data must not be a string.")
        if data is None:
            return b"", self.content_type

        fields = to_key_val_dict(data or "")
        try:
            body = json.dumps(fields)
        except:
            body = json.dumps(fields, encoding='latin-1')

        return str(body).encode(), self.content_type
141229
def _encode_text(name, value, dummy0, dummy1):
    """"""
    value = _utf_8_encode(value)[0]
    return b"\x02" + name + _PACK_INT(len(value) + 1) + value + b"\x00"
345562
function encodeAttachmentMessage(buffer, offset, message) {
    if (message == undefined)
        throw Error('Specify message');
    offset += encodeString(buffer, message, offset);
    return offset;
}
579168
function encode(hexString) {
	// Convert to array of bytes
	var bytes = Buffer.from(hexString, "hex");
	var encoded = base32.stringify(bytes);

	// strip padding & lowercase
	return encoded.replace(/(=+)$/, '').toLowerCase();
}
1220945
def EncodeUnicode(text):
  
  if type(text) == type(u''):
    return text.encode(OUTPUT_ENCODING)
  else:
    return text
1009801
protected function decodeBody()
    {
        if(is_object($this->message)){
            foreach ($this->message->types as $typeMessage) {
                if(is_object($this->message->$typeMessage)){
                    switch ($this->message->$typeMessage->structure->encoding) {
                        case 3:
                            $this->message->$typeMessage->body = imap_base64($this->message->$typeMessage->body);
                            break;
                        case 4:
                            $this->message->$typeMessage->body = imap_qprint($this->message->$typeMessage->body);
                            break;
                    }
                }

                if(is_object($this->message->$typeMessage)){
                    if ($this->message->$typeMessage->charset) {
                        $this->message->$typeMessage->body = $this->convertToUtf8($this->message->$typeMessage->body, $this->message->$typeMessage->charset);
                    }
                }
            }
        }
    }
439363
def encode_request(name, from_, to):
    
    client_message = ClientMessage(payload_size=calculate_size(name, from_, to))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_int(from_)
    client_message.append_int(to)
    client_message.update_frame_length()
    return client_message
1324320
function encodeHeaderValue(key) {
  var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';

  key = normalizeHeaderKey(key);

  switch (key) {
    case 'From':
    case 'Sender':
    case 'To':
    case 'Cc':
    case 'Bcc':
    case 'Reply-To':
      return convertAddresses(parseAddresses(value));

    case 'Message-Id':
    case 'In-Reply-To':
    case 'Content-Id':
      value = value.replace(/\r?\n|\r/g, ' ');

      if (value.charAt(0) !== '<') {
        value = '<' + value;
      }

      if (value.charAt(value.length - 1) !== '>') {
        value = value + '>';
      }
      return value;

    case 'References':
      value = [].concat.apply([], [].concat(value).map(function () {
        var elm = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
        return elm.replace(/\r?\n|\r/g, ' ').trim().replace(/<[^>]*>/g, function (str) {
          return str.replace(/\s/g, '');
        }).split(/\s+/);
      })).map(function (elm) {
        if (elm.charAt(0) !== '<') {
          elm = '<' + elm;
        }
        if (elm.charAt(elm.length - 1) !== '>') {
          elm = elm + '>';
        }
        return elm;
      });

      return value.join(' ').trim();

    default:
      return (0, _emailjsMimeCodec.mimeWordsEncode)((value || '').toString().replace(/\r?\n|\r/g, ' '), 'B');
  }
}
722022
def encode(msg):
    
    msg = bytes(msg)
    return END + msg.replace(ESC, ESC + ESC_ESC).replace(END, ESC + ESC_END) + END
150570
def encode(data, checksum=True):
    """"""

    if checksum:
        data = data + utils.hash256(data)[:4]
    v, prefix = to_long(256, lambda x: x, iter(data))
    data = from_long(v, prefix, BASE58_BASE, lambda v: BASE58_ALPHABET[v])
    return data.decode("utf8")
619005
def encode(self, message, k=None):
        ''''''
        if not k: k = self.k
        message, _ = self.pad(message, k=k)
        if self.algo == 1:
            mesecc = self.ecc_manager.encode(message, k=k)
        elif self.algo == 2:
            mesecc = self.ecc_manager.encode_fast(message, k=k)
        elif self.algo == 3 or self.algo == 4:
            mesecc = rs_encode_msg(message, self.n-k, fcr=self.fcr, gen=self.g[self.n-k])
            #mesecc = rs_encode_msg_precomp(message, self.n-k, fcr=self.fcr, gen=self.g[self.n-k])

        ecc = mesecc[len(message):]
        return ecc
317621
private static JsJmsMessage decodeTextBody(String body) throws MessageDecodeFailedException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "decodeTextBody");
        JsJmsTextMessage result = new JsJmsTextMessageImpl(MfpConstants.CONSTRUCTOR_NO_OP);
        if (body != null) {
            result.setText(URLDecode(body));
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "decodeTextBody");
        return result;
    }
968097
def body_as_str(self, encoding='UTF-8'):
        
        data = self.body
        try:
            return "".join(b.decode(encoding) for b in data)
        except TypeError:
            return six.text_type(data)
        except:  # pylint: disable=bare-except
            pass
        try:
            return data.decode(encoding)
        except Exception as e:
            raise TypeError("Message data is not compatible with string type: {}".format(e))
979431
function convertBody(buffer, headers) {
	if (typeof convert !== 'function') {
		throw new Error('The package `encoding` must be installed to use the textConverted() function');
	}

	const ct = headers.get('content-type');
	let charset = 'utf-8';
	let res, str;

	// header
	if (ct) {
		res = /charset=([^;]*)/i.exec(ct);
	}

	// no charset in content type, peek at response body for at most 1024 bytes
	str = buffer.slice(0, 1024).toString();

	// html5
	if (!res && str) {
		res = /<meta.+?charset=(['"])(.+?)\1/i.exec(str);
	}

	// html4
	if (!res && str) {
		res = /<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(str);

		if (res) {
			res = /charset=(.*)/i.exec(res.pop());
		}
	}

	// xml
	if (!res && str) {
		res = /<\?xml.+?encoding=(['"])(.+?)\1/i.exec(str);
	}

	// found charset
	if (res) {
		charset = res.pop();

		// prevent decode issues when sites use incorrect encoding
		// ref: https://hsivonen.fi/encoding-menu/
		if (charset === 'gb2312' || charset === 'gbk') {
			charset = 'gb18030';
		}
	}

	// turn raw buffers into a single utf-8 buffer
	return convert(
		buffer,
		'UTF-8',
		charset
	).toString();
}
486279
function encode(text, lang, encoding) {

    // ISO/IANA language code, but we're not enforcing
    if (!lang) { lang = 'en'; }

    var encoded = util.stringToBytes(lang + text);
    encoded.unshift(lang.length);

    return encoded;
}