(num)
| 18 | |
| 19 | |
| 20 | def encode_num(num): |
| 21 | if num == 0: |
| 22 | return b'' |
| 23 | abs_num = abs(num) |
| 24 | negative = num < 0 |
| 25 | result = bytearray() |
| 26 | while abs_num: |
| 27 | result.append(abs_num & 0xff) |
| 28 | abs_num >>= 8 |
| 29 | # if the top bit is set, |
| 30 | # for negative numbers we ensure that the top bit is set |
| 31 | # for positive numbers we ensure that the top bit is not set |
| 32 | if result[-1] & 0x80: |
| 33 | if negative: |
| 34 | result.append(0x80) |
| 35 | else: |
| 36 | result.append(0) |
| 37 | elif negative: |
| 38 | result[-1] |= 0x80 |
| 39 | return bytes(result) |
| 40 | |
| 41 | |
| 42 | def decode_num(element): |
no outgoing calls
no test coverage detected