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() {
|
||||
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}
|
||||
*/
|
||||
|
||||
Bloom.prototype.toRaw = function toRaw() {
|
||||
var size = this.getSize();
|
||||
var bw = new StaticWriter(size);
|
||||
|
||||
Bloom.prototype.toWriter = function toWriter(bw) {
|
||||
bw.writeVarBytes(this.filter);
|
||||
bw.writeU32(this.n);
|
||||
bw.writeU32(this.tweak);
|
||||
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) {
|
||||
var br = new BufferReader(data);
|
||||
return this.fromReader(new BufferReader(data));
|
||||
};
|
||||
|
||||
this.filter = br.readVarBytes();
|
||||
this.n = br.readU32();
|
||||
this.tweak = br.readU32();
|
||||
this.update = br.readU8();
|
||||
/**
|
||||
* Instantiate bloom filter from buffer reader.
|
||||
* @param {BufferReader} br
|
||||
* @returns {Bloom}
|
||||
*/
|
||||
|
||||
assert(constants.filterFlagsByVal[this.update] != null, 'Bad filter flag.');
|
||||
|
||||
return this;
|
||||
Bloom.fromReader = function fromReader(br) {
|
||||
return new Bloom().fromReader(br);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -2577,9 +2577,7 @@ Wallet.prototype.toRaw = function toRaw() {
|
||||
|
||||
Wallet.prototype.fromRaw = function fromRaw(data) {
|
||||
var br = new BufferReader(data);
|
||||
var network;
|
||||
|
||||
network = Network.fromMagic(br.readU32());
|
||||
var network = Network.fromMagic(br.readU32());
|
||||
|
||||
this.wid = br.readU32();
|
||||
this.id = br.readVarString('ascii');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user