Improve usability of bitfield.encode
This commit is contained in:
parent
df5e024004
commit
3d5968bcc1
|
@ -520,6 +520,9 @@ var bitfield = function(size) {
|
|||
encode: function(features) {
|
||||
var buf = new Buffer(bytesize);
|
||||
buf.fill(0);
|
||||
if (!Array.isArray(features)) {
|
||||
features = [features];
|
||||
}
|
||||
features.forEach(function(feature) {
|
||||
assert(feature >= 0, "Bad feature");
|
||||
assert(feature <= (size - 1), "Bad feature");
|
||||
|
|
2
test.js
2
test.js
|
@ -259,6 +259,7 @@ describe("Common structures", function() {
|
|||
|
||||
it("should encode", function() {
|
||||
expect(serviceFeatures.encode([serviceFeatures.NODE_NETWORK]).toString("hex")).to.equal("0000000000000001");
|
||||
expect(serviceFeatures.encode(serviceFeatures.NODE_NETWORK).toString("hex")).to.equal("0000000000000001");
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -269,6 +270,7 @@ describe("Common structures", function() {
|
|||
|
||||
it("should encode", function() {
|
||||
expect(pubkeyFeatures.encode([pubkeyFeatures.INCLUDE_DESTINATION, pubkeyFeatures.DOES_ACK]).toString("hex")).to.equal("c0000000");
|
||||
expect(pubkeyFeatures.encode(pubkeyFeatures.INCLUDE_DESTINATION).toString("hex")).to.equal("40000000");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user