Created
June 21, 2018 14:11
-
-
Save ELGReeND/cffe98304efc328466d7075e528a2036 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c.on('data', function(data) { | |
if(_data[c['_id']].length != 0) { //Если буфер не пустой | |
_data[c['_id']] = Buffer.concat([_data[c['_id']], data]); //Добавить новые данные к существующим | |
}else{ | |
_data[c['_id']] = data; //Добавить данные | |
} | |
var len = _data[c['_id']].readUInt16BE(0); //Взять длину сообщения (первые 2 байта - это до 64к) | |
if (_data[c['_id']].length >= len) { //Если размер буфера равен или больше размера сообщения | |
var mess = JSON.parse( _data[c['_id']].slice(2, len).toJSON() ); //берем сообщение | |
_data[c['_id']] = Buffer.from( _data[c['_id']].slice(len+2) ); //убираем из буфера то что взяли | |
gmCallback.scr_nodejs_onData(c['_id'], mess); //отправляем | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment