/* Copyright 2022 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #include "tensorflow/compiler/mlir/lite/experimental/remat/metadata_util.h" #include <string> #include <utility> #include <vector> namespace { // We serialize unsigneds as protobuf varints, i.e., in chunks of 7 bits each. constexpr int kMod = …; void Serialize(std::string* out, uint32_t value) { … } bool Parse(const char** data, size_t* size, uint32_t* out) { … } // Signed ints are zigzag-encoded as unsigned varints, [..., -2, -1, 0, 1, 2, // ...] -> // [..., 3, 1, 0, 2, 4, ...]. void Serialize(std::string* out, int32_t value) { … } bool Parse(const char** data, size_t* size, int32_t* out) { … } // Pairs are serialized as the concatenation of their elements' serialization. template <class First, class Second> void Serialize(std::string* out, const std::pair<First, Second>& in) { … } template <class First, class Second> bool Parse(const char** data, size_t* size, std::pair<First, Second>* out) { … } // Vectors are serialized as the concetation of the serialization of their size // and the the serializations of their elements. template <class Value> void Serialize(std::string* out, const std::vector<Value>& in) { … } template <class T> bool Parse(const char** data, size_t* size, std::vector<T>* out) { … } } // namespace namespace tflite { std::string SerializeModelControlDependencies( const ModelControlDependencies& in) { … } bool ParseModelControlDependencies(const char* data, size_t size, ModelControlDependencies* out) { … } } // namespace tflite