Helper to retrieve the UTF8 representation of a message
payload (hexadecimal representation).

@return string
481645
public function toPlain($hex = null)
    {
        if (empty($this->payload) && empty($hex))
            return "";

        $plain = "";
        $payload = $hex ?: $this->payload;
        for ($c = 0, $cnt = strlen($payload); $c < $cnt; $c += 2) {
            $hex = substr($payload, $c, 2);
            $decimal = hexdec($hex);
            $plain  .= chr($decimal);
        }

        return ($this->plain = $plain);
    }
295021
def to_utf8
            detect_encoding

            utf16 = self.encoding.to_utf16be(self.value)
            utf16.slice!(0, Encoding::UTF16BE::BOM.size)

            utf16.encode("utf-8", "utf-16be")
        end
270830
private function parseSignedInt32()
    {
        try {
            $result = \unpack('N', $this->buffer)[1];

            if ($result & 0x80000000) {
                return $result - 0x100000000;
            }

            return $result;
        } finally {
            $this->buffer = mb_orig_substr($this->buffer, 4);
        }
    }
1233727
public function getBytes()
    {
        $bytes = '';

        foreach (range(-2, -32, 2) as $step) {
            $bytes = chr(hexdec(substr($this->getHex(), $step, 2))) . $bytes;
        }

        return $bytes;
    }
622501
public int getMessageLength(){
		if(this.identifierRegex == null){
			return 1;
		}
		try {
			return this.identifierRegex.getBytes("UTF-16BE").length + 1;
		} catch (UnsupportedEncodingException e) {
			log.error("Unable to decode UTF-16BE String: {}", e);
			return 1;
		}
	}
463467
def _handle_utf8_payload(body, properties):
        
        if 'content_encoding' not in properties:
            properties['content_encoding'] = 'utf-8'
        encoding = properties['content_encoding']
        if compatibility.is_unicode(body):
            body = body.encode(encoding)
        elif compatibility.PYTHON3 and isinstance(body, str):
            body = bytes(body, encoding=encoding)
        return body
459615
public function keyIdentifier64(): string
    {
        $id = substr($this->keyIdentifier(), -8);
        $c = (ord($id[0]) & 0x0f) | 0x40;
        $id[0] = chr($c);
        return $id;
    }
498470
public String toHexString() {
    final StringBuilder buf = new StringBuilder(24);

    for (final byte b : toByteArray()) {
      buf.append(String.format("%02x", b & 0xff));
    }

    return buf.toString();
  }
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);
                    }
                }
            }
        }
    }
606458
function serialize($charset_encoding='')
		{
			if ($charset_encoding != '')
				$this->content_type = 'application/json; charset=' . $charset_encoding;
			else
				$this->content_type = 'application/json';
			$this->payload = serialize_jsonrpcresp($this, $this->id, $charset_encoding);
			return $this->payload;
		}
1070330
public function getUtf8Value()
    {
        if (strcasecmp($this->encoding, 'utf8') == 0  
            || strcasecmp($this->encoding, 'utf-8') == 0 
        ) {
                return $this->value;
        } else {

            return (PHP_OS != 'AIX') ? iconv($this->encoding, 'UTF-8', $this->value) : iconv('ISO8859-1', 'UTF-8', $this->value);
        }
    }
965994
private static function utf8ToUnicode($str)
    {
        $unicode = array();
        $values = array();
        $lookingFor = 1;

        for ($i = 0; $i < strlen($str); $i++ ) {
            $thisValue = ord($str[$i]);

            if ($thisValue < 128) {
                $unicode[] = $thisValue;
            }
            else {
                if (count($values) == 0) {
                    $lookingFor = $thisValue < 224 ? 2 : 3;
                }

                $values[] = $thisValue;

                if (count($values) == $lookingFor) {
                    $number = $lookingFor == 3
                              ? (($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64)
                              : (($values[0] % 32) * 64) + ($values[1] % 64);

                    $unicode[] = $number;
                    $values = array();
                    $lookingFor = 1;
                }
            }
        }

        return $unicode;
    }
1365014
function byte2hexStr(byte) {
  var hexByteMap = "0123456789ABCDEF";
  var str = "";
  str += hexByteMap.charAt(byte >> 4);
  str += hexByteMap.charAt(byte & 0x0f);
  return str;
}
392085
public function getBytes()
    {
        $bytes = '';

        $hex = $this->toString();
        $hex = str_replace('-', '', $hex);

        foreach (range(-2, -32, 2) as $step) {
            $bytes = chr(hexdec(substr($hex, $step, 2))) . $bytes;
        }

        return $bytes;
    }
396909
public function getMacKey()
    {
        $key = $this->config['key'];

        $hexStrKey = substr($key, 0, 38);
        $hexFinal = "" . substr($key, 38, 2) . "00";

        $cca0 = ord($hexFinal);

        if ($cca0 > 70 && $cca0 < 97) {
            $hexStrKey .= chr($cca0 - 23) . substr($hexFinal, 1, 1);
        } else {
            if (substr($hexFinal, 1, 1) == "M") {
                $hexStrKey .= substr($hexFinal, 0, 1) . "0";
            } else {
                $hexStrKey .= substr($hexFinal, 0, 2);
            }
        }

        return pack("H*", $hexStrKey);
    }
176928
public static function utf8($value)
    {
        if (is_string($value) && mb_detect_encoding($value, "UTF-8", TRUE) != "UTF-8") {
            return utf8_encode($value);
        } else {
            return $value;
        }
    }
1160541
final public function createSendableMessage(): string
    {
        $variableHeader = $this->createVariableHeader();
        $this->logger->debug('Created variable header', ['variableHeader' => base64_encode($variableHeader)]);
        $payload = $this->createPayload();
        $this->logger->debug('Created payload', ['payload' => base64_encode($payload)]);
        $fixedHeader = $this->createFixedHeader(strlen($variableHeader . $payload));
        $this->logger->debug('Created fixed header', ['fixedHeader' => base64_encode($fixedHeader)]);

        return $fixedHeader . $variableHeader . $payload;
    }