def frame_message(self):
if self._frame is not None:<EOL><INDENT>self.discard_message()<EOL><DEDENT>panes = []<EOL>p = origin = self._origin<EOL>extent = self._extent<EOL>while p < extent:<EOL><INDENT>available = extent - p<EOL>if available < <NUM_LIT:2>:<EOL><INDENT>break<EOL><DEDENT>chunk_size, = struct_unpack("<STR_LIT>", self._view[p:(p + <NUM_LIT:2>)])<EOL>p += <NUM_LIT:2><EOL>if chunk_size == <NUM_LIT:0>:<EOL><INDENT>self._limit = p<EOL>self._frame = MessageFrame(memoryview(self._view[origin:self._limit]), panes)<EOL>return True<EOL><DEDENT>q = p + chunk_size<EOL>panes.append((p - origin, q - origin))<EOL>p = q<EOL><DEDENT>return False<EOL>
Construct a frame around the first complete message in the buffer.