def check_buffer(buf, namespace=False):
    
    if len(buf) < HEADER_LENGTH:
        return None
    
    (datlen,) = struct.unpack('<1I', buf[0:4])
    msglen = datlen + HEADER_LENGTH
    if len(buf) < msglen:
        return None

    (connid,) = struct.unpack('<1I', buf[4:8])
    msgdat = buf[HEADER_LENGTH:msglen]
    
    buf[0:msglen] = b''

    object_hook = namespace_wrapper if namespace else None

    msgstr = msgdat.decode()  # Decode UTF-8
    msgobj = json.loads(msgstr, object_hook=object_hook)  # Decode JSON
    if (type(msgobj) not in [dict, types.SimpleNamespace]):
        raise ValueError('Message was not an object')
    return (connid, msgdat, msgobj)
Given a mutable bytearray, see if it begins with a complete message.
dataset/ETHPy150Open erkyrath/tworld/lib/twcommon/wcproto.py/check_buffer