1 /** 2 * Copyright 2020 Huawei Technologies Co., Ltd 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 MINDSPORE_LITE_SRC_COMMON_STRING_UTIL_H_ 18 #define MINDSPORE_LITE_SRC_COMMON_STRING_UTIL_H_ 19 #include <vector> 20 #include <string> 21 #include <utility> 22 #include "src/tensor.h" 23 #include "src/common/log_adapter.h" 24 #include "tools/common/option.h" 25 #include "include/errorcode.h" 26 #include "include/lite_utils.h" 27 28 namespace mindspore { 29 namespace lite { 30 typedef struct StringPack { 31 int len = 0; 32 const char *data = nullptr; 33 } StringPack; 34 35 // example of string tensor: 36 // 2, 0, 0, 0 # int32, num of strings 37 // 16, 0, 0, 0 # int32, offset of 0-th string 38 // 21, 0, 0, 0 # int32, offset of 1-th string 39 // 30, 0, 0, 0 # int32, total length of tensor data 40 // 'h', 'e', 'l', 'l', 'o', 'h', 'o', 'w', 'a', 'r', 'e', 'y', 'o', 'u' # char, "hello", "how are you" 41 std::vector<StringPack> ParseTensorBuffer(Tensor *tensor); 42 std::vector<StringPack> ParseStringBuffer(const void *data); 43 44 int WriteStringsToTensor(Tensor *tensor, const std::vector<StringPack> &string_buffer); 45 int WriteSeperatedStringsToTensor(Tensor *tensor, const std::vector<std::vector<StringPack>> &string_buffer); 46 47 int GetStringCount(const void *data); 48 int GetStringCount(Tensor *tensor); 49 uint64_t StringHash64(const char *s, size_t len); 50 } // namespace lite 51 } // namespace mindspore 52 #endif // MINDSPORE_LITE_SRC_COMMON_STRING_UTIL_H_ 53