Fix double Buffer.concat
Though I'm not sure is it gonna be faster.
This commit is contained in:
parent
782b7e7d27
commit
3ca97f294c
|
@ -217,8 +217,9 @@ var addr = exports.addr = {
|
||||||
*/
|
*/
|
||||||
encodePayload: function(addrs) {
|
encodePayload: function(addrs) {
|
||||||
assert(addrs.length <= 1000, "Too many address entires");
|
assert(addrs.length <= 1000, "Too many address entires");
|
||||||
var addrsBuf = Buffer.concat(addrs.map(structs.net_addr.encode));
|
var addrBufs = addrs.map(structs.net_addr.encode);
|
||||||
return Buffer.concat([structs.var_int.encode(addrs.length), addrsBuf]);
|
var bufs = [structs.var_int.encode(addrs.length)].concat(addrBufs);
|
||||||
|
return Buffer.concat(bufs);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -281,8 +282,8 @@ var inv = exports.inv = {
|
||||||
*/
|
*/
|
||||||
encodePayload: function(inventory) {
|
encodePayload: function(inventory) {
|
||||||
assert(inventory.length <= 50000, "Too many inventory entires");
|
assert(inventory.length <= 50000, "Too many inventory entires");
|
||||||
var invBuf = Buffer.concat(inventory);
|
var bufs = [structs.var_int.encode(inventory.length)].concat(inventory);
|
||||||
return Buffer.concat([structs.var_int.encode(inventory.length), invBuf]);
|
return Buffer.concat(bufs);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -190,7 +190,7 @@ var message = exports.message = {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode message structure.
|
* Decode message.
|
||||||
* NOTE: `payload` is copied, `rest` references input buffer.
|
* NOTE: `payload` is copied, `rest` references input buffer.
|
||||||
* @param {Buffer} buf - Buffer that starts with encoded message
|
* @param {Buffer} buf - Buffer that starts with encoded message
|
||||||
* @return {DecodeResult}
|
* @return {DecodeResult}
|
||||||
|
@ -227,7 +227,7 @@ var message = exports.message = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode message structure.
|
* Encode message.
|
||||||
* @param {string} command - Message command
|
* @param {string} command - Message command
|
||||||
* @param {Bufer} payload - Message payload
|
* @param {Bufer} payload - Message payload
|
||||||
* @return {Buffer} Encoded message structure.
|
* @return {Buffer} Encoded message structure.
|
||||||
|
@ -610,8 +610,9 @@ exports.var_int_list = {
|
||||||
* @return {Buffer} Encoded `var_int_list`.
|
* @return {Buffer} Encoded `var_int_list`.
|
||||||
*/
|
*/
|
||||||
encode: function(list) {
|
encode: function(list) {
|
||||||
var listBuf = Buffer.concat(list.map(var_int.encode));
|
var var_ints = list.map(var_int.encode);
|
||||||
return Buffer.concat([var_int.encode(list.length), listBuf]);
|
var bufs = [var_int.encode(list.length)].concat(var_ints);
|
||||||
|
return Buffer.concat(bufs);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user