read_varint reads a variable integer from a stream
(s)
| 72 | |
| 73 | |
| 74 | def read_varint(s): |
| 75 | '''read_varint reads a variable integer from a stream''' |
| 76 | i = s.read(1)[0] |
| 77 | if i == 0xfd: |
| 78 | # 0xfd means the next two bytes are the number |
| 79 | return little_endian_to_int(s.read(2)) |
| 80 | elif i == 0xfe: |
| 81 | # 0xfe means the next four bytes are the number |
| 82 | return little_endian_to_int(s.read(4)) |
| 83 | elif i == 0xff: |
| 84 | # 0xff means the next eight bytes are the number |
| 85 | return little_endian_to_int(s.read(8)) |
| 86 | else: |
| 87 | # anything else is just the integer |
| 88 | return i |
| 89 | |
| 90 | |
| 91 | def encode_varint(i): |
no test coverage detected