1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "utils/encdec/include/data_decoder.h" 17 18 namespace OHOS { 19 namespace AI { 20 template<> DecodeOneParameter(std::string & val)21int DataDecoder::DecodeOneParameter(std::string &val) 22 { 23 size_t len = 0; 24 if (DecodeOneParameter(len) != RETCODE_SUCCESS) { 25 return RETCODE_FAILURE; 26 } 27 if (len == 0) { 28 val = ""; 29 return RETCODE_SUCCESS; 30 } 31 if (!Ensure(len)) { 32 HILOGE("[Encdec]Memory read out of boundary"); 33 return RETCODE_FAILURE; 34 } 35 val.assign(buffer_ + pos_, buffer_ + pos_ + len); 36 37 pos_ += len; 38 return RETCODE_SUCCESS; 39 } 40 } // namespace AI 41 } // namespace OHOS 42