def bufferize(worker: AbstractWorker, plan: "Plan") -> PlanPB: """ This function takes the attributes of a Plan and saves them in a Protobuf message Args: worker (AbstractWorker): the worker doing the serialization plan (Plan): a Plan object Returns: PlanPB: a Protobuf message holding the unique attributes of the Plan object """ protobuf_plan = PlanPB() sy.serde.protobuf.proto.set_protobuf_id(protobuf_plan.id, plan.id) protobuf_plan.role.CopyFrom( sy.serde.protobuf.serde._bufferize(worker, plan.role)) protobuf_plan.include_state = plan.include_state protobuf_plan.is_built = plan.is_built protobuf_plan.name = plan.name protobuf_plan.tags.extend(plan.tags) if protobuf_plan.description: protobuf_plan.description = plan.description if plan.torchscript: protobuf_plan.torchscript = plan.torchscript.save_to_buffer() return protobuf_plan
def bufferize(worker: AbstractWorker, plan: "Plan") -> PlanPB: """ This function takes the attributes of a Plan and saves them in a Protobuf message Args: worker (AbstractWorker): the worker doing the serialization plan (Plan): a Plan object Returns: PlanPB: a Protobuf message holding the unique attributes of the Plan object """ protobuf_plan = PlanPB() sy.serde.protobuf.proto.set_protobuf_id(protobuf_plan.id, plan.id) protobuf_actions = [ sy.serde.protobuf.serde._bufferize(worker, action) for action in plan.actions ] protobuf_plan.actions.extend(protobuf_actions) protobuf_plan.state.CopyFrom( sy.serde.protobuf.serde._bufferize(worker, plan.state)) protobuf_plan.include_state = plan.include_state protobuf_plan.is_built = plan.is_built protobuf_plan.name = plan.name protobuf_plan.tags.extend(plan.tags) if protobuf_plan.description: protobuf_plan.description = plan.description if type(plan.placeholders) == type(dict()): placeholders = plan.placeholders.values() else: placeholders = plan.placeholders protobuf_placeholders = [ sy.serde.protobuf.serde._bufferize(worker, placeholder) for placeholder in placeholders ] protobuf_plan.placeholders.extend(protobuf_placeholders) return protobuf_plan