Skip to content

Commit 0c45de1

Browse files
committed
common/features: helper to pretty-print feature bits.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 0b945d3 commit 0c45de1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

common/features.c

+15
Original file line numberDiff line numberDiff line change
@@ -497,3 +497,18 @@ void towire_feature_set(u8 **pptr, const struct feature_set *fset)
497497
towire_u8_array(pptr, fset->bits[i], tal_bytelen(fset->bits[i]));
498498
}
499499
}
500+
501+
const char *fmt_featurebits(const tal_t *ctx, const u8 *featurebits)
502+
{
503+
size_t size = tal_count(featurebits);
504+
char *fmt = tal_strdup(ctx, "");
505+
const char *prefix = "";
506+
507+
for (size_t i = 0; i < size * 8; i++) {
508+
if (feature_is_set(featurebits, i)) {
509+
tal_append_fmt(&fmt, "%s%zu", prefix, i);
510+
prefix = ",";
511+
}
512+
}
513+
return fmt;
514+
}

common/features.h

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ void set_feature_bit(u8 **ptr, u32 bit);
7171
/* Given two featurebit vectors, combine them by applying a logical OR. */
7272
u8 *featurebits_or(const tal_t *ctx, const u8 *f1 TAKES, const u8 *f2 TAKES);
7373

74+
/* Good for debugging: returns comma-separated string of bits. */
75+
const char *fmt_featurebits(const tal_t *ctx, const u8 *featurebits);
76+
7477
/* BOLT #9:
7578
*
7679
* Flags are numbered from the least-significant bit, at bit 0 (i.e. 0x1,

0 commit comments

Comments
 (0)