mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
Merge pull request #11 from binlain/master
Fix length calculation when encoding as binary
This commit is contained in:
@@ -347,10 +347,10 @@ exports.encodePayloadAsBinary = function (packets, callback) {
|
||||
|
||||
function encodeOne(p, doneCallback) {
|
||||
exports.encodePacket(p, function(packet) {
|
||||
var encodingLength = '' + packet.length;
|
||||
var sizeBuffer = new Buffer(encodingLength.length + 2);
|
||||
|
||||
if (typeof packet === 'string') {
|
||||
var encodingLength = '' + Buffer.byteLength(packet, "utf8");
|
||||
var sizeBuffer = new Buffer(encodingLength.length + 2);
|
||||
sizeBuffer[0] = 0; // is a string (not true binary = 0)
|
||||
for (var i = 0; i < encodingLength.length; i++) {
|
||||
sizeBuffer[i + 1] = parseInt(encodingLength[i], 10);
|
||||
@@ -358,7 +358,9 @@ exports.encodePayloadAsBinary = function (packets, callback) {
|
||||
sizeBuffer[sizeBuffer.length - 1] = 255;
|
||||
return doneCallback(null, Buffer.concat([sizeBuffer, new Buffer(packet, 'utf8')]));
|
||||
}
|
||||
|
||||
|
||||
var encodingLength = '' + packet.length;
|
||||
var sizeBuffer = new Buffer(encodingLength.length + 2);
|
||||
sizeBuffer[0] = 1; // is binary (true binary = 1)
|
||||
for (var i = 0; i < encodingLength.length; i++) {
|
||||
sizeBuffer[i + 1] = parseInt(encodingLength[i], 10);
|
||||
|
||||
Reference in New Issue
Block a user