Write a string up to 2**32 bytes long.  Assume UTF-8 encoding.

@param $s

@return Writer
8036
public function writeLongStr($s)
    {
        $this->flushBits();
        $this->writeLong(strlen($s));
        $this->out .= $s;
        return $this;
    }
1044958
public function buildLenEncodedBinary($s)
    {
        if ($s === null) {
            return "\251";
        }

        $l = mb_orig_strlen($s);

        if ($l <= 250) {
            return chr($l) . $s;
        }

        if ($l <= 0xFFFF) {
            return "\252" . Binary::int2bytes(2, true) . $s;
        }

        if ($l <= 0xFFFFFF) {
            return "\254" . Binary::int2bytes(3, true) . $s;
        }

        return Binary::int2bytes(8, $l, true) . $s;
    }
204953
public function write($chars)
    {
        if (!isset($this->charReader)) {
            $this->charReader = $this->charReaderFactory->getReaderFor(
                $this->charset);
        }

        $startLength = $this->charReader->getInitialByteSize();

        $fp = fopen('php://memory', 'w+b');
        fwrite($fp, $chars);
        unset($chars);
        fseek($fp, 0, SEEK_SET);

        $buffer = [0];
        $buf_pos = 1;
        $buf_len = 1;
        $has_datas = true;
        do {
            $bytes = [];
            // Buffer Filing
            if ($buf_len - $buf_pos < $startLength) {
                $buf = array_splice($buffer, $buf_pos);
                $new = $this->reloadBuffer($fp, 100);
                if ($new) {
                    $buffer = array_merge($buf, $new);
                    $buf_len = count($buffer);
                    $buf_pos = 0;
                } else {
                    $has_datas = false;
                }
            }
            if ($buf_len - $buf_pos > 0) {
                $size = 0;
                for ($i = 0; $i < $startLength && isset($buffer[$buf_pos]); ++$i) {
                    ++$size;
                    $bytes[] = $buffer[$buf_pos++];
                }
                $need = $this->charReader->validateByteSequence(
                    $bytes, $size);
                if ($need > 0) {
                    if ($buf_len - $buf_pos < $need) {
                        $new = $this->reloadBuffer($fp, $need);

                        if ($new) {
                            $buffer = array_merge($buffer, $new);
                            $buf_len = count($buffer);
                        }
                    }
                    for ($i = 0; $i < $need && isset($buffer[$buf_pos]); ++$i) {
                        $bytes[] = $buffer[$buf_pos++];
                    }
                }
                $this->array[] = $bytes;
                ++$this->array_size;
            }
        } while ($has_datas);

        fclose($fp);
    }
1248467
public function writeString($string)
    {
        // $maxLen = 2^16 -1 = max val of unsigned short integer.
        $maxLen = 65535;
        $len = strlen($string);

        if ($len > $maxLen) {
            $len = $maxLen;
            $string = substr($string, 0, $maxLen);
        }

        try {
            $this->getStream()->write(pack('S', $len) . $string);
        } catch (StreamException $e) {
            $this->handleStreamException($e, BinaryStreamAccessException::STRING, false);
        }
    }
414703
public function write($string)
    {
        $chunked = $this->getChunkedString($string);
        $this->position += strlen($chunked);
        return $this->stream->write($chunked);
    }
1296970
public function write_shortstr($s)
    {
        $len = mb_strlen($s, 'ASCII');
        if ($len > 255) {
            throw new AMQPInvalidArgumentException('String too long');
        }

        $this->write_octet($len);
        $this->out .= $s;

        return $this;
    }
811464
public function writeLongLong($n)
    {
        $this->flushBits();
        $this->out .= implode('', Writer::chrByteSplit($n, 8));
        return $this;
    }
420008
def writeBytes(self, s):
        
        l = len(s)

        if l > 0xffff:
            self.writeType(TYPE_LONGSTRING)
        else:
            self.writeType(TYPE_STRING)

        if l > 0xffff:
            self.stream.write_ulong(l)
        else:
            self.stream.write_ushort(l)

        self.stream.write(s)
729308
public function buildLenEncodedBinary($s)
    {
        if ($s === null) {
            return "\251";
        }

        $l = mb_orig_strlen($s);

        if ($l <= 250) {
            return chr($l) . $s;
        }

        if ($l <= 0xFFFF) {
            return "\252" . $this->int2bytes(2, $l) . $s;
        }

        if ($l <= 0xFFFFFF) {
            return "\254" . $this->int2bytes(3, $l) . $s;
        }

        return $this->int2bytes(8, $l) . $s;
    }
805704
public static function encodeString(string $s, int $maxLength = null): string
    {
        static $table;
        if ($table === null) {
            foreach (\array_merge(\range("\x00", "\x1F"), \range("\x7F", "\xFF")) as $ch) {
                $table[$ch] = '\x' . \str_pad(\dechex(\ord($ch)), 2, '0', STR_PAD_LEFT);
            }
            $table['\\'] = '\\\\';
            $table["\r"] = '\r';
            $table["\n"] = '\n';
            $table["\t"] = '\t';
        }

        if ($maxLength && \strlen($s) > $maxLength) { // shortens to $maxLength in UTF-8 or longer
            $s = \mb_substr($tmp = $s, 0, $maxLength);
            $shortened = $s !== $tmp;
        }

        if (\preg_match('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{10FFFF}]#u', $s) || \preg_last_error()) { // is binary?
            if ($maxLength && \strlen($s) > $maxLength) {
                $s = \substr($s, 0, $maxLength);
                $shortened = true;
            }
            $s = \strtr($s, $table);
        }

        return $s . (empty($shortened) ? '' : ' ... ');
    }
1002046
public function writeString($str) {

            $strref = strlen($str) << 1 | 0x01;
            $this->writeInt($strref);
            $this->stream->writeBuffer($str);

        }
310392
public function write($string)
    {
        $this->content = substr_replace($this->content, $string, $this->position, 0);
        $len = strlen($string);
        $this->position += $len;
        return $len;
    }
420056
@ThreadSafe public void stringEncode(String s, Writer writer) throws IOException {
		char[] carr = s.toCharArray();
		int len = carr.length;
		for(int i = 0; i < len; i++) {
			char c = carr[i];
			switch (c) {
			case '"':
				writer.write("\\\"");
				break;
			case '/':
				writer.write(escapeSlash ? "\\/" : "/");
				break;
			case '\\':
				writer.write("\\\\");
				break;
			case '\b':
				writer.write("\\b");
				break;
			case '\f':
				writer.write("\\f");
				break;
			case '\n':
				writer.write("\\n");
				break;
			case '\r':
				writer.write("\\r");
				break;
			case '\t':
				writer.write("\\t");
				break;
			default:
				if(unicodeEscapeAll) {
					if(c < 127) {
						writer.append(c);
					} else {
						String hex = Integer.toHexString(c);
						writer.write("\\u");
						switch (hex.length()) {
						case 1:
							writer.write("000");
							break;
						case 2:
							writer.write("00");
							break;
						case 3:
							writer.write("0");
							break;
						default:
							break;
						}
						writer.write(Integer.toHexString(c));
					}
				} else {
					writer.append(c);
				}
				break;
			}
		}
	}
1176337
public function serializeLong(int $long = null)
    {
        if (null === $long) {
            // long on 8 bytes always
            $uint8 = array_merge($this->serializeInt(null), $this->serializeInt(0));
        }
        else {
            // prepend size on 4 bytes
            $uint64L = $this->serializeInt($long);
            $uint64H = $this->serializeInt($long >> 32);

            $uint8 = array_merge($uint64L, $uint64H);
            if (($len = count($uint8)) === 8) 
                // job done
                return $uint8;

            // right padding to 8 bytes
            for ($i = 0, $done = 8 - $len; $i < $done; $i++) {
                array_push($uint8, 0);
            }
        }

        return $uint8;
    }
1014929
def write_utf(self, s):
        """"""
        utfstr = s.encode('utf-8')
        length = len(utfstr)
        if length > 64:
            raise NamePartTooLongException
        self.write_byte(length)
        self.write_string(utfstr, length)
1342219
public function write($string)
    {
        if (strlen($string) !== $bytesWritten = fwrite($this->getHandle(), $string)) {
            throw new RuntimeException(
                'Buffer could not be written to stream.'
            );
        }

        return $bytesWritten;
    }
909193
public static function to_unicode($s)
	{
		if (! ReflectionTypeHint::isValid()) return false;
		if (is_null($s)) return $s;

		$s2 = null;
		#since PHP-5.3.x iconv() little faster then mb_convert_encoding()
		if (function_exists('iconv')) $s2 = @iconv('UTF-8', 'UCS-4BE', $s);
		elseif (function_exists('mb_convert_encoding')) $s2 = @mb_convert_encoding($s, 'UCS-4BE', 'UTF-8');
		if (is_string($s2)) return array_values(unpack('N*', $s2));
		if ($s2 !== null) return false;

		$a = self::str_split($s);
		if ($a === false) return false;
		return array_map(array(__CLASS__, 'ord'), $a);
	}