예제 #1
0
 def _data_chunk_iterator_upload_edge_snapshot(serialized_edge_snapshot, lease,
                                               data_chunk_byte_size):
     total_bytes_size = len(serialized_edge_snapshot)
     num_chunks = math.ceil(total_bytes_size / data_chunk_byte_size)
     for i in range(num_chunks):
         start_index = i * data_chunk_byte_size
         end_index = (i + 1) * data_chunk_byte_size
         chunk = data_chunk_pb2.DataChunk(total_size=total_bytes_size)
         if (end_index > total_bytes_size):
             chunk.data = serialized_edge_snapshot[start_index:total_bytes_size]
         else:
             chunk.data = serialized_edge_snapshot[start_index:end_index]
         req = graph_nav_pb2.UploadWaypointSnapshotRequest(lease=lease, chunk=chunk)
         yield req
예제 #2
0
 def chunk_message(message, data_chunk_byte_size):
     """Take a message, and split it into data chunks
     Args:
         data_chunk_byte_size: max size of each streamed message
     """
     serialized = message.SerializeToString()
     total_bytes_size = len(serialized)
     num_chunks = math.ceil(total_bytes_size / data_chunk_byte_size)
     for i in range(num_chunks):
         start_index = i * data_chunk_byte_size
         end_index = min(total_bytes_size, (i + 1) * data_chunk_byte_size)
         chunk = data_chunk_pb2.DataChunk(total_size=total_bytes_size)
         chunk.data = serialized[start_index:end_index]
         yield chunk