Bitfield.toString

This commit is contained in:
Kagami Hiiragi 2015-02-23 20:55:30 +03:00
parent 5f96a5d893
commit 849e76ca23
2 changed files with 18 additions and 0 deletions

View File

@ -984,6 +984,16 @@ var Bitfield = function(size) {
return this;
};
BitfieldInner.prototype.toString = function() {
var i;
var str = "";
for (i = 0; i < this.buffer.length; i++) {
// Should be faster than pushing to array and joining on v8.
str += ("0000000" + this.buffer[i].toString(2)).slice(-8);
}
return "<Bitfield:" + str + ">";
};
return BitfieldInner;
};

View File

@ -455,6 +455,14 @@ describe("Common structures", function() {
expect(ServicesBitfield().set([ServicesBitfield.NODE_NETWORK]).buffer.toString("hex")).to.equal("0000000000000001");
expect(ServicesBitfield().set(ServicesBitfield.NODE_NETWORK).buffer.toString("hex")).to.equal("0000000000000001");
});
it("should implement toString", function() {
var services = ServicesBitfield().set([
ServicesBitfield.NODE_NETWORK,
ServicesBitfield.NODE_GATEWAY,
]);
expect(services.toString()).to.equal("<Bitfield:0000000000000000000000000000000000000000000000000000000000000101>");
});
});
describe("pubkey features", function() {