Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(message[index++] << 16) |
(message[index++] << 24);
// Unpack and decompress if the message is OP_COMPRESSED
if (type === opcodes.OP_COMPRESSED) {
const requestID = message.readInt32LE(4);
const responseTo = message.readInt32LE(8);
const originalOpcode = message.readInt32LE(16);
const uncompressedSize = message.readInt32LE(20);
const compressorID = message.readUInt8(24);
const compressedData = message.slice(25);
let uncompressedData;
switch (compressorID) {
case compressorIDs.snappy:
uncompressedData = Snappy.uncompressSync(compressedData);
break;
case compressorIDs.zlib:
uncompressedData = zlib.inflateSync(compressedData);
break;
default:
uncompressedData = compressedData;
}
if (uncompressedData.length !== uncompressedSize) {
throw new Error(
'corrupt wire protocol message: uncompressed message is not the correct size'
);
}
// Reconstruct the msgHeader of the uncompressed opcode
const newMsgHeader = Buffer(MESSAGE_HEADER_SIZE);
function createStringTable(data) {
//create a stringtable
//console.error(data);
//extract the native buffer from the string_data ByteBuffer, with the offset removed
var buf = data.string_data.toBuffer();
if (data.data_compressed) {
//decompress the string data with snappy
//early source 2 replays may use LZSS, we can detect this by reading the first four bytes of buffer
buf = snappy.uncompressSync(buf);
}
//pass the buffer and parse string table data from it
var items = parseStringTableData(buf, data.num_entries, data.user_data_fixed_size, data.user_data_size);
//console.error(items);
//remove the buf and replace with items, which is a decoded version of it
data.string_data = {};
// Insert the items into the table as an object
items.forEach(function(it) {
data.string_data[it.index] = it;
});
/*
// Apply the updates to baseline state
if t.name == "instancebaseline" {
p.updateInstanceBaseline()
}
*/
//msgCompressed: = (command & dota.EDemoCommands_DEM_IsCompressed) == dota.EDemoCommands_DEM_IsCompressed
var msgType = command & ~dota.EDemoCommands.DEM_IsCompressed;
var msgCompressed = (command & dota.EDemoCommands.DEM_IsCompressed) === dota.EDemoCommands.DEM_IsCompressed;
// Read the tick that the message corresponds with.
//tick: = p.reader.readVarUint32()
// This appears to actually be an int32, where a -1 means pre-game.
/*
if tick == 4294967295 {
tick = 0
}
*/
if (tick === 4294967295) {
tick = 0;
}
if (msgCompressed) {
buf = snappy.uncompressSync(buf);
}
var msg = {
tick: tick,
typeId: msgType,
size: size,
isCompressed: msgCompressed,
data: buf
};
return cb(null, msg);
});
});
//msgCompressed: = (command & dota.EDemoCommands_DEM_IsCompressed) == dota.EDemoCommands_DEM_IsCompressed
var msgType = command & ~dota.EDemoCommands.DEM_IsCompressed;
var msgCompressed = (command & dota.EDemoCommands.DEM_IsCompressed) === dota.EDemoCommands.DEM_IsCompressed;
// Read the tick that the message corresponds with.
//tick: = p.reader.readVarUint32()
// This appears to actually be an int32, where a -1 means pre-game.
/*
if tick == 4294967295 {
tick = 0
}
*/
if (tick === 4294967295) {
tick = 0;
}
if (msgCompressed) {
buf = snappy.uncompressSync(buf);
}
var msg = {
tick: tick,
typeId: msgType,
size: size,
isCompressed: msgCompressed,
data: buf
};
return cb(err, msg);
});
});
var fs = require('fs')
, path = require('path')
, snappy = require('snappy')
, snappyjs = require('../../snappy.js')
, input = fs.readFileSync(path.resolve(__dirname, '../fixtures/urls.10K-compressed.bin'))
console.log('uncompress')
console.time('snappy')
for(var i = 0; i < 100; ++i)
snappy.uncompressSync(input)
console.timeEnd('snappy')
console.time('snappy.js')
for(var i = 0; i < 100; ++i)
snappyjs.uncompress(input)
console.timeEnd('snappy.js')
console.log('isValidCompressed')
console.time('snappy')
for(var i = 0; i < 100; ++i)
snappy.isValidCompressedSync(input)
console.timeEnd('snappy')
console.time('snappy.js')
for(var i = 0; i < 100; ++i)
snappyjs.isValidCompressed(input)
}).add('node-snappy#uncompress', function () {
var i
if (data.repeatedTimes) {
for (i = 0; i < data.repeatedTimes; i++) {
snappy.uncompressSync(data.compressedBuffer)
}
} else {
snappy.uncompressSync(data.compressedBuffer)
}
}).add('snappyjs#uncompress', function () {
var i
protected _deserializeValue (value: Buffer): Uint8Array | null {
return bufferToU8a(
this._isCompressed
? snappy.uncompressSync(value)
: value
);
}
protected _deserializeValue (value: Buffer): Uint8Array | null {
return bufferToU8a(
this._isCompressed
? snappy.uncompressSync(value)
: value
);
}
router.on('message',function(){
var args = Array.apply(null, arguments);
if(debug){
var aux=args.slice();
if(aux[3]=='c') aux[4]=snappy.uncompressSync(aux[4]);
showArguments(aux);
}
router.send([args[2],'',args[0],args[3],args[4]]);
});
socket.on('message',function(){
var args = Array.apply(null, arguments);
if(args[2]=='c') args[3]=snappy.uncompressSync(args[3]);
if(debug) showArguments(args);
var message=JSON.parse(args[3]);
if(message.rpc=='appendEntries') appendEntries(message.term,message.leaderId,message.prevLogIndex,message.prevLogTerm,message.entries,message.leaderCommit);
else if(message.rpc=='replyAppendEntries') replyAppendEntries(message.term,message.followerId,message.entriesToAppend,message.success);
else if(message.rpc=='requestVote') requestVote(message.term,message.candidateId,message.lastLogIndex,message.lastLogTerm);
else if(message.rpc=='replyVote') replyVote(message.term,message.voteGranted);
else if(message.rpc=='installSnapshot') installSnapshot(message.term,message.leaderId,message.lastIncludedIndex,message.lastIncludedTerm,message.offset,message.data,message.done);
});