From f3a998037a3f3295ff94a62a523aee38b569c4ea Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Thu, 18 Jul 2024 21:19:43 +0000 Subject: [PATCH] Improve encode_nix32 comment --- .../base/fetch_and_unpack_nix_substituter.rs | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/action/base/fetch_and_unpack_nix_substituter.rs b/src/action/base/fetch_and_unpack_nix_substituter.rs index 7c9f918..66528be 100644 --- a/src/action/base/fetch_and_unpack_nix_substituter.rs +++ b/src/action/base/fetch_and_unpack_nix_substituter.rs @@ -614,17 +614,26 @@ fn encode_nix32(input: &[u8]) -> String { // The output is backwards and bits are grouped // from the least significant bit in each byte // instead of the most significant bit. - // e.g. encoding "Meow" gives us: + // e.g. for a 4-byte input, bits are mapped from input to output like this: + // Out No.: 5 5 5 6 6 6 6 6 | 3 4 4 4 4 4 5 5 | 2 2 2 2 3 3 3 3 | 0 0 1 1 1 1 1 2 + // Out Bit: 2 1 0 4 3 2 1 0 | 0 4 3 2 1 0 4 3 | 3 2 1 0 4 3 2 1 | 1 0 4 3 2 1 0 4 + // + // where "Out No." is the index of the output charater responsible for a given bit; + // and "Out Bit" is the value of a given bit within the output character, + // with 4 being most significant and 0 being least significant. + // + // for "Meow" we'd get: // Char: M (0x4d) e (0x65) o (0x6f) w (0x77) // Value: 0 1 0 0 1 1 0 1 | 0 1 1 0 0 1 0 1 | 0 1 1 0 1 1 1 1 | 0 1 1 1 0 1 1 1 // Out No.: 5 5 5 6 6 6 6 6 | 3 4 4 4 4 4 5 5 | 2 2 2 2 3 3 3 3 | 0 0 1 1 1 1 1 2 - // Out Bit: 2 1 0 4 3 2 1 0 | 0 5 4 3 2 1 4 3 | 3 2 1 0 4 3 2 1 | 1 0 4 3 2 1 0 4 - // - // where "Out No." is the index of the output charater responsible for a given bit, - // and 2**"Out Bit" is the value of a given bit for its output character. - // - // In this example, characters 0 to 6 have values - // 0x01, 0x1b, 0x16, 0x1e, 0x19, 0xa, 0xd. + // Out Bit: 2 1 0 4 3 2 1 0 | 0 4 3 2 1 0 4 3 | 3 2 1 0 4 3 2 1 | 1 0 4 3 2 1 0 4 + // 6: 01101 (0x0d) + // 5: 01010 (0x0a) + // 4: 11001 (0x19) + // 3: 11110 (0x1e) + // 2: 10110 (0x16) + // 1: 11011 (0x1b) + // 0: 00001 (0x01) // Indexing into the alphabet gives us "1vnyrad" for char_no in 0..length {