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_PARSER_H_ 18 #define FCP_AGGREGATION_PROTOCOL_CHECKPOINT_PARSER_H_ 19 20 #include <memory> 21 #include <string> 22 #include <vector> 23 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 parsing a checkpoint from a blob 31 // and returning a set of named tensors. 32 class CheckpointParser { 33 public: 34 virtual ~CheckpointParser() = default; 35 36 // Gets a tensor by name. 37 virtual absl::StatusOr<Tensor> GetTensor(const std::string& name) const = 0; 38 }; 39 40 // Describes an abstract factory for creating instances of CheckpointParser. 41 class CheckpointParserFactory { 42 public: 43 virtual ~CheckpointParserFactory() = default; 44 45 // Creates an instance of CheckpointParser with the provided serialized 46 // checkpoint content. 47 virtual absl::StatusOr<std::unique_ptr<CheckpointParser>> Create( 48 const absl::Cord& serialized_checkpoint) const = 0; 49 }; 50 51 } // namespace fcp::aggregation 52 53 #endif // FCP_AGGREGATION_PROTOCOL_CHECKPOINT_PARSER_H_ 54