common/features: helper to pretty-print feature bits.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2021-06-04 11:23:55 +09:30
parent 2ffd344299
commit 325d33a902
2 changed files with 18 additions and 0 deletions

View File

@@ -497,3 +497,18 @@ void towire_feature_set(u8 **pptr, const struct feature_set *fset)
towire_u8_array(pptr, fset->bits[i], tal_bytelen(fset->bits[i]));
}
}
const char *fmt_featurebits(const tal_t *ctx, const u8 *featurebits)
{
size_t size = tal_count(featurebits);
char *fmt = tal_strdup(ctx, "");
const char *prefix = "";
for (size_t i = 0; i < size * 8; i++) {
if (feature_is_set(featurebits, i)) {
tal_append_fmt(&fmt, "%s%zu", prefix, i);
prefix = ",";
}
}
return fmt;
}