def get_graph_proto(): """Get graph proto.""" with open(GRAPH_PROTO_FILE, 'rb') as f: content = f.read() graph = ms_graph_pb2.GraphProto() graph.ParseFromString(content) return graph
def init_graph_handler(): """Init graph proto.""" with open(GRAPH_PROTO_FILE, 'rb') as file_handler: content = file_handler.read() graph = ms_graph_pb2.GraphProto() graph.ParseFromString(content) graph_handler = GraphHandler() graph_handler.put(graph) return graph_handler
def _get_graph_chunks(self, graph_name='graph_0'): """Get graph chunks.""" with open(GRAPH_PROTO_FILE, 'rb') as file_handle: content = file_handle.read() size = len(content) graph = ms_graph_pb2.GraphProto() graph.ParseFromString(content) graph.name = graph_name content = graph.SerializeToString() self._leaf_node = [node.full_name for node in graph.node] # the max limit of grpc data size is 4kb # split graph into 3kb per chunk chunk_size = 1024 * 1024 * 3 chunks = [] for index in range(0, size, chunk_size): sub_size = min(chunk_size, size - index) sub_chunk = Chunk(buffer=content[index: index + sub_size]) chunks.append(sub_chunk) chunks[-1].finished = True return chunks