1 /* 2 * Copyright (c) 2023 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 "encoded_param.h" 17 18 #include "hilog/log.h" 19 #include "raw_data_encoder.h" 20 #include "securec.h" 21 22 #undef LOG_DOMAIN 23 #define LOG_DOMAIN 0xD002D08 24 25 #undef LOG_TAG 26 #define LOG_TAG "HISYSEVENT_ENCODED_PARAM" 27 28 namespace OHOS { 29 namespace HiviewDFX { 30 namespace Encoded { EncodedParam(const std::string & key)31EncodedParam::EncodedParam(const std::string& key) 32 { 33 key_ = key; 34 } 35 ~EncodedParam()36EncodedParam::~EncodedParam() 37 { 38 } 39 GetKey()40std::string& EncodedParam::GetKey() 41 { 42 return key_; 43 } 44 SetRawData(std::shared_ptr<RawData> rawData)45void EncodedParam::SetRawData(std::shared_ptr<RawData> rawData) 46 { 47 rawData_ = rawData; 48 } 49 GetRawData()50std::shared_ptr<RawData> EncodedParam::GetRawData() 51 { 52 if (!hasEncoded_) { 53 hasEncoded_ = Encode(); 54 } 55 return rawData_; 56 } 57 Encode()58bool EncodedParam::Encode() 59 { 60 hasEncoded_ = EncodeKey() && EncodeValueType() && EncodeValue(); 61 return hasEncoded_; 62 } 63 EncodeKey()64bool EncodedParam::EncodeKey() 65 { 66 if (rawData_ == nullptr) { 67 return false; 68 } 69 if (!RawDataEncoder::StringValueEncoded(*rawData_, key_)) { 70 HILOG_ERROR(LOG_CORE, "The key of customized value encoded failded."); 71 return false; 72 } 73 return true; 74 } 75 } // namespace Encoded 76 } // namespace HiviewDFX 77 } // namespace OHOS