Encode an unsigned integer as a protobuf varint.
(n: int)
| 52 | |
| 53 | |
| 54 | def varint(n: int) -> bytes: |
| 55 | """Encode an unsigned integer as a protobuf varint.""" |
| 56 | out = bytearray() |
| 57 | while True: |
| 58 | b = n & 0x7F |
| 59 | n >>= 7 |
| 60 | if n: |
| 61 | out.append(b | 0x80) |
| 62 | else: |
| 63 | out.append(b) |
| 64 | return bytes(out) |
| 65 | |
| 66 | |
| 67 | def tag(field: int, wire: int) -> bytes: |
no test coverage detected