Add BitVec.toBoolArray() helper function (#5585)

This commit is contained in:
Jaco
2023-04-07 09:24:11 +03:00
committed by GitHub
parent 9052f16e0f
commit d51ddc70f9
4 changed files with 87 additions and 4 deletions
@@ -722,15 +722,22 @@ export class PortableRegistry extends Struct implements ILookup {
? [a, b]
: [b, a];
// NOTE: Currently the BitVec type is one-way only, i.e. we only use it to decode, not
// re-encode stuff. As such we ignore the msb/lsb identifier given by bitOrderType, or rather
// we don't pass it though at all (all displays in LSB)
if (!BITVEC_NS.includes(bitOrder.namespace || '')) {
if (!bitOrder.namespace || !BITVEC_NS.includes(bitOrder.namespace)) {
throw new Error(`Unexpected bitOrder found as ${bitOrder.namespace || '<unknown>'}`);
} else if (bitStore.info !== TypeDefInfo.Plain || bitStore.type !== 'u8') {
throw new Error(`Only u8 bitStore is currently supported, found ${bitStore.type}`);
}
const isLsb = BITVEC_NS_LSB.includes(bitOrder.namespace);
if (!isLsb) {
// TODO To remove this limitation, we need to pass an extra info flag
// through to the TypeDef (Here we could potentially re-use something
// like index (???) to indicate and ensure we use it to pass to the
// BitVec constructor - which does handle this type)
throw new Error(`Only LSB BitVec is currently supported, found ${bitOrder.namespace}`);
}
return {
info: TypeDefInfo.Plain,
type: 'BitVec'