Bitfield.toString
This commit is contained in:
parent
5f96a5d893
commit
849e76ca23
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user