1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef FCP_AGGREGATION_PROTOCOL_CHECKPOINT_BUILDER_H_ 18 #define FCP_AGGREGATION_PROTOCOL_CHECKPOINT_BUILDER_H_ 19 20 #include <memory> 21 #include <string> 22 23 #include "absl/status/status.h" 24 #include "absl/status/statusor.h" 25 #include "absl/strings/cord.h" 26 #include "fcp/aggregation/core/tensor.h" 27 28 namespace fcp::aggregation { 29 30 // Describes an abstract interface for building and formatting a checkpoint 31 // from a set of named tensors. 32 class CheckpointBuilder { 33 public: 34 virtual ~CheckpointBuilder() = default; 35 36 // Adds a tensor to the checkpoint. 37 virtual absl::Status Add(const std::string& name, const Tensor& tensor) = 0; 38 39 // Builds and formats the checkpoint. 40 virtual absl::StatusOr<absl::Cord> Build() = 0; 41 }; 42 43 // Describes an abstract factory for creating instances of CheckpointBuilder. 44 class CheckpointBuilderFactory { 45 public: 46 virtual ~CheckpointBuilderFactory() = default; 47 48 // Creates an instance of CheckpointBuilder. 49 virtual std::unique_ptr<CheckpointBuilder> Create() const = 0; 50 }; 51 52 } // namespace fcp::aggregation 53 54 #endif // FCP_AGGREGATION_PROTOCOL_CHECKPOINT_BUILDER_H_ 55