in polymetis/python/polymetis/robot_interface.py [0:0]
def _get_msg_generator(scripted_module) -> Generator:
"""Given a scripted module, return a generator of its serialized bits
as byte chunks of max size MAX_BYTES_PER_MSG."""
# Write into bytes buffer
buffer = io.BytesIO()
torch.jit.save(scripted_module, buffer)
buffer.seek(0)
# Create policy generator
def msg_generator():
# A generator which chunks a scripted module into messages of
# size MAX_BYTES_PER_MSG and send these messages to the server.
while True:
chunk = buffer.read(MAX_BYTES_PER_MSG)
if not chunk: # end of buffer
break
msg = ControllerChunk(torchscript_binary_chunk=chunk)
yield msg
return msg_generator