def extract_message(cls, raw_bytes):
if b':' not in raw_bytes:
if len(raw_bytes) > 10:
raise FramingError(
'Length information missing: %s' % raw_bytes)
return None, raw_bytes
msg_len, rest = raw_bytes.split(b':', 1)
try:
msg_len = int(msg_len)
except ValueError:
raise FramingError('Invalid length: %s' % raw_bytes)
if msg_len < 0:
raise FramingError('Negative length: %s' % raw_bytes)
if len(rest) < msg_len + 1:
return None, raw_bytes
else:
if six.indexbytes(rest, msg_len) != 44:
raise FramingError(
'Missing correct end marker: %s' % raw_bytes)
return rest[:msg_len], rest[(msg_len + 1):]
评论列表
文章目录