You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was having problems receiving bytes messages for use with googles / chobies protocolbuffers php implementation with this STOMP implementation. Sending to a Java client worked like a charm, but the return to PHP failed trying to deserialize the protocol buffer bytes.
When executing $msg = $con->readFrame, it truncated the bytes by doing a trim on the message body removing all whitespace. The solution is the following new function for Stomp.php, whatch this line only stripping "\x00" instead of all whitespace :
$frame = new StompFrame($command, $headers, trim($body, "\x00"));
/**
* Read response frame from server for binairy messages
*
* @return StompFrame False when no frame to read
*/
public function readFrameBinairy ()
{
if (!$this->hasFrameToRead()) {
return false;
}
$rb = 1024;
$data = '';
$end = false;
do {
$read = fread($this->_socket, $rb);
if ($read === false) {
$this->_reconnect();
return $this->readFrame();
}
$data .= $read;
if (strpos($data, "\x00") !== false) {
$end = true;
$data = rtrim($data, "\n");
}
$len = strlen($data);
} while ($len < 2 || $end == false);
list ($header, $body) = explode("\n\n", $data, 2);
$header = explode("\n", $header);
$headers = array();
$command = null;
foreach ($header as $v) {
if (isset($command)) {
list ($name, $value) = explode(':', $v, 2);
$headers[$name] = $value;
} else {
$command = $v;
}
}
$frame = new StompFrame($command, $headers, trim($body, "\x00"));
if (isset($frame->headers['transformation']) && $frame->headers['transformation'] == 'jms-map-json') {
require_once 'Stomp/Map.php';
return new StompMessageMap($frame);
} else {
return $frame;
}
return $frame;
}
Thanks to my colleague Jan Grävell for his excelent PHP knowlledge.
The text was updated successfully, but these errors were encountered:
I am having a similar problem. I cant vouch for the code above, but I am working with a feed that gzips the content of the messages. Then when the body is trimmed it breaks the gzip encoded strings. So it would be great if there was a way of telling it to not trim the body on some frames.
I was having problems receiving bytes messages for use with googles / chobies protocolbuffers php implementation with this STOMP implementation. Sending to a Java client worked like a charm, but the return to PHP failed trying to deserialize the protocol buffer bytes.
When executing $msg = $con->readFrame, it truncated the bytes by doing a trim on the message body removing all whitespace. The solution is the following new function for Stomp.php, whatch this line only stripping "\x00" instead of all whitespace :
$frame = new StompFrame($command, $headers, trim($body, "\x00"));
/**
* Read response frame from server for binairy messages
*
* @return StompFrame False when no frame to read
*/
public function readFrameBinairy ()
{
if (!$this->hasFrameToRead()) {
return false;
}
$rb = 1024;
$data = '';
$end = false;
do {
$read = fread($this->_socket, $rb);
if ($read === false) {
$this->_reconnect();
return $this->readFrame();
}
$data .= $read;
if (strpos($data, "\x00") !== false) {
$end = true;
$data = rtrim($data, "\n");
}
$len = strlen($data);
} while ($len < 2 || $end == false);
list ($header, $body) = explode("\n\n", $data, 2);
$header = explode("\n", $header);
$headers = array();
$command = null;
foreach ($header as $v) {
if (isset($command)) {
list ($name, $value) = explode(':', $v, 2);
$headers[$name] = $value;
} else {
$command = $v;
}
}
$frame = new StompFrame($command, $headers, trim($body, "\x00"));
if (isset($frame->headers['transformation']) && $frame->headers['transformation'] == 'jms-map-json') {
require_once 'Stomp/Map.php';
return new StompMessageMap($frame);
} else {
return $frame;
}
return $frame;
}
Thanks to my colleague Jan Grävell for his excelent PHP knowlledge.
The text was updated successfully, but these errors were encountered: