(obj)
| 400 | |
| 401 | @staticmethod |
| 402 | def encode(obj): |
| 403 | r = bytearray(0) |
| 404 | if obj.value == 0: |
| 405 | return bytes(r) |
| 406 | neg = obj.value < 0 |
| 407 | absvalue = -obj.value if neg else obj.value |
| 408 | while absvalue: |
| 409 | r.append(absvalue & 0xFF) |
| 410 | absvalue >>= 8 |
| 411 | if r[-1] & 0x80: |
| 412 | r.append(0x80 if neg else 0) |
| 413 | elif neg: |
| 414 | r[-1] |= 0x80 |
| 415 | return bytes([len(r)]) + r |
| 416 | |
| 417 | @staticmethod |
| 418 | def decode(vch): |
no outgoing calls