packets: more serialization nonsense.
This commit is contained in:
parent
fcc7f41438
commit
14c9a37cd9
1259
lib/net/packets.js
1259
lib/net/packets.js
File diff suppressed because it is too large
Load Diff
@ -1321,7 +1321,7 @@ MTX.prototype.inspect = function inspect() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
MTX.prototype.format = function format() {
|
MTX.prototype.format = function format() {
|
||||||
return TX.prototype.inspect.call(this, this.view);
|
return TX.prototype.format.call(this, this.view);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -188,16 +188,37 @@ Bloom.prototype.getSize = function getSize() {
|
|||||||
* @returns {Buffer}
|
* @returns {Buffer}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Bloom.prototype.toRaw = function toRaw() {
|
Bloom.prototype.toWriter = function toWriter(bw) {
|
||||||
var size = this.getSize();
|
|
||||||
var bw = new StaticWriter(size);
|
|
||||||
|
|
||||||
bw.writeVarBytes(this.filter);
|
bw.writeVarBytes(this.filter);
|
||||||
bw.writeU32(this.n);
|
bw.writeU32(this.n);
|
||||||
bw.writeU32(this.tweak);
|
bw.writeU32(this.tweak);
|
||||||
bw.writeU8(this.update);
|
bw.writeU8(this.update);
|
||||||
|
return bw;
|
||||||
|
};
|
||||||
|
|
||||||
return bw.render();
|
/**
|
||||||
|
* Serialize bloom filter.
|
||||||
|
* @returns {Buffer}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Bloom.prototype.toRaw = function toRaw() {
|
||||||
|
var size = this.getSize();
|
||||||
|
return this.toWriter(new StaticWriter(size)).render();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject properties from buffer reader.
|
||||||
|
* @private
|
||||||
|
* @param {BufferReader} br
|
||||||
|
*/
|
||||||
|
|
||||||
|
Bloom.prototype.fromReader = function fromReader(br) {
|
||||||
|
this.filter = br.readVarBytes();
|
||||||
|
this.n = br.readU32();
|
||||||
|
this.tweak = br.readU32();
|
||||||
|
this.update = br.readU8();
|
||||||
|
assert(constants.filterFlagsByVal[this.update] != null, 'Bad filter flag.');
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -207,16 +228,17 @@ Bloom.prototype.toRaw = function toRaw() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Bloom.prototype.fromRaw = function fromRaw(data) {
|
Bloom.prototype.fromRaw = function fromRaw(data) {
|
||||||
var br = new BufferReader(data);
|
return this.fromReader(new BufferReader(data));
|
||||||
|
};
|
||||||
|
|
||||||
this.filter = br.readVarBytes();
|
/**
|
||||||
this.n = br.readU32();
|
* Instantiate bloom filter from buffer reader.
|
||||||
this.tweak = br.readU32();
|
* @param {BufferReader} br
|
||||||
this.update = br.readU8();
|
* @returns {Bloom}
|
||||||
|
*/
|
||||||
|
|
||||||
assert(constants.filterFlagsByVal[this.update] != null, 'Bad filter flag.');
|
Bloom.fromReader = function fromReader(br) {
|
||||||
|
return new Bloom().fromReader(br);
|
||||||
return this;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -2577,9 +2577,7 @@ Wallet.prototype.toRaw = function toRaw() {
|
|||||||
|
|
||||||
Wallet.prototype.fromRaw = function fromRaw(data) {
|
Wallet.prototype.fromRaw = function fromRaw(data) {
|
||||||
var br = new BufferReader(data);
|
var br = new BufferReader(data);
|
||||||
var network;
|
var network = Network.fromMagic(br.readU32());
|
||||||
|
|
||||||
network = Network.fromMagic(br.readU32());
|
|
||||||
|
|
||||||
this.wid = br.readU32();
|
this.wid = br.readU32();
|
||||||
this.id = br.readVarString('ascii');
|
this.id = br.readVarString('ascii');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user