RiakPBC.prototype._splitPacket = function (pkt) { var self = this; var pos = 0; var len; if (self.numBytesAwaiting > 0) { len = Math.min(pkt.length, self.numBytesAwaiting); var oldBuf = self.resBuffers[self.resBuffers.length - 1]; var newBuf = new Buffer(oldBuf.length + len); oldBuf.copy(newBuf, 0); pkt.slice(0, len).copy(newBuf, oldBuf.length); self.resBuffers[self.resBuffers.length - 1] = newBuf; pos = len; self.numBytesAwaiting -= len; } else { self.resBuffers = []; } while (pos < pkt.length) { len = butils.readInt32(pkt, pos); self.numBytesAwaiting = len + 4 - pkt.length; self.resBuffers.push(pkt.slice(pos + 4, Math.min(pos + len + 4, pkt.length))); pos += len + 4; } };
function splitPacket(pkt) { var pos = 0, len; if (numBytesAwaiting > 0) { len = Math.min(pkt.length, numBytesAwaiting); var oldBuf = resBuffers[resBuffers.length - 1]; var newBuf = new Buffer(oldBuf.length + len); oldBuf.copy(newBuf, 0); pkt.slice(0, len).copy(newBuf, oldBuf.length); resBuffers[resBuffers.length - 1] = newBuf; pos = len; numBytesAwaiting -= len; } else { resBuffers = []; } while (pos < pkt.length) { len = butils.readInt32(pkt, pos); numBytesAwaiting = len + 4 - pkt.length; resBuffers.push(pkt.slice(pos + 4, Math.min(pos + len + 4, pkt.length))); pos += len + 4; } }