Decodes data encoded with LOWER_SPECIAL encoding. Args: data (bytes): The encoded data. Returns: str: The decoded string.
(self, data: bytes)
| 124 | raise ValueError(f"Unexpected encoding flag: {encoding}") |
| 125 | |
| 126 | def _decode_lower_special(self, data: bytes) -> str: |
| 127 | """ |
| 128 | Decodes data encoded with LOWER_SPECIAL encoding. |
| 129 | |
| 130 | Args: |
| 131 | data (bytes): The encoded data. |
| 132 | |
| 133 | Returns: |
| 134 | str: The decoded string. |
| 135 | """ |
| 136 | decoded = [] |
| 137 | num_bits = len(data) * 8 # Total number of bits in the data |
| 138 | strip_last_char = (data[0] & 0x80) != 0 # Check the first bit of the first byte |
| 139 | bit_index = 1 |
| 140 | bit_mask = 0b11111 |
| 141 | while bit_index + 5 <= num_bits and not (strip_last_char and (bit_index + 2 * 5 > num_bits)): |
| 142 | byte_index = bit_index // 8 |
| 143 | intra_byte_index = bit_index % 8 |
| 144 | # Extract the 5-bit character value across byte boundaries if needed |
| 145 | char_value = ((data[byte_index] << 8) | (data[byte_index + 1] if byte_index + 1 < len(data) else 0)) >> (11 - intra_byte_index) & bit_mask |
| 146 | bit_index += 5 |
| 147 | decoded.append(self._decode_lower_special_char(char_value)) |
| 148 | |
| 149 | return "".join(decoded) |
| 150 | |
| 151 | def _decode_lower_upper_digit_special(self, data: bytes) -> str: |
| 152 | """ |
no test coverage detected