getBaseXResliceDecoder function

VariableSizeDecoder<String> getBaseXResliceDecoder(
  1. String alphabet,
  2. int bits
)

Returns a decoder for base-X encoded strings using bit re-slicing.

This decoder deserializes base-X encoded strings by re-slicing the bits of a byte array into custom-sized chunks and mapping them to a specified alphabet.

For more details, see getBaseXResliceCodec.

Implementation

VariableSizeDecoder<String> getBaseXResliceDecoder(String alphabet, int bits) {
  return VariableSizeDecoder<String>(
    read: (rawBytes, offset) {
      final bytes = offset == 0 || offset <= -rawBytes.length
          ? rawBytes
          : rawBytes.sublist(offset);
      if (bytes.isEmpty) return ('', rawBytes.length);
      final charIndices = _reslice(bytes.toList(), 8, bits, true);
      return (charIndices.map((i) => alphabet[i]).join(), rawBytes.length);
    },
  );
}