private static function encodeResponse(Clazz $responseClass, $object, $wasThrown, $flags, $serializationPolicy) { $stream = new ServerSerializationStreamWriter($serializationPolicy); $stream->setFlags($flags); $stream->prepareToWrite(); if ($responseClass !== Void::typeClass()) { $stream->serializeValue($object, $responseClass); } $bufferStr = ($wasThrown ? '//EX' : '//OK') . (string) $stream; return $bufferStr; }