first the size prefix and then the corresponding msg payload
(buf: bytes)
| 75 | |
| 76 | |
| 77 | def read_msg(buf: bytes) -> tuple: |
| 78 | """first the size prefix and then the corresponding msg payload""" |
| 79 | |
| 80 | if len(buf) < 4: |
| 81 | return (0, "", buf) |
| 82 | size = struct.unpack("!I", buf[0:4])[0] |
| 83 | logger.debug("read_msg: size: %d", size) |
| 84 | if len(buf) - 4 >= size: |
| 85 | text = struct.unpack("!%ds" % size, buf[4 : 4 + size])[0] |
| 86 | return (size, text, buf[4 + size :]) |
| 87 | else: |
| 88 | return (size, "", buf) |
| 89 | |
| 90 | |
| 91 | def read_fields(buf: bytes) -> tuple: |