Format an integer using a variable-length binary encoding.
(n: int)
| 214 | |
| 215 | |
| 216 | def format_int(n: int) -> bytes: |
| 217 | """Format an integer using a variable-length binary encoding.""" |
| 218 | if n < 128: |
| 219 | a = [n] |
| 220 | else: |
| 221 | a = [] |
| 222 | while n > 0: |
| 223 | a.insert(0, n & 0x7F) |
| 224 | n >>= 7 |
| 225 | for i in range(len(a) - 1): |
| 226 | # If the highest bit is set, more 7-bit digits follow |
| 227 | a[i] |= 0x80 |
| 228 | return bytes(a) |
| 229 | |
| 230 | |
| 231 | def format_str_literal(s: str) -> bytes: |
no test coverage detected
searching dependent graphs…