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/encoded_param.h"
17 
18 #include "encoded/raw_data_encoder.h"
19 #include "hiview_logger.h"
20 #include "securec.h"
21 
22 namespace OHOS {
23 namespace HiviewDFX {
24 namespace EventRaw {
25 DEFINE_LOG_TAG("HiView-EncodedParam");
EncodedParam(const std::string & key)26 EncodedParam::EncodedParam(const std::string& key)
27 {
28     key_ = key;
29 }
30 
~EncodedParam()31 EncodedParam::~EncodedParam()
32 {
33 }
34 
GetKey()35 std::string& EncodedParam::GetKey()
36 {
37     return key_;
38 }
39 
GetRawData()40 RawData& EncodedParam::GetRawData()
41 {
42     if (!hasEncoded_) {
43         hasEncoded_ = Encode();
44     }
45     return rawData_;
46 }
47 
AsUint64(uint64_t & dest)48 bool EncodedParam::AsUint64(uint64_t& dest)
49 {
50     return false;
51 }
52 
AsInt64(int64_t & dest)53 bool EncodedParam::AsInt64(int64_t& dest)
54 {
55     return false;
56 }
57 
AsDouble(double & dest)58 bool EncodedParam::AsDouble(double& dest)
59 {
60     return false;
61 }
62 
AsString(std::string & dest)63 bool EncodedParam::AsString(std::string& dest)
64 {
65     return false;
66 }
67 
AsUint64Vec(std::vector<uint64_t> & dest)68 bool EncodedParam::AsUint64Vec(std::vector<uint64_t>& dest)
69 {
70     return false;
71 }
72 
AsInt64Vec(std::vector<int64_t> & dest)73 bool EncodedParam::AsInt64Vec(std::vector<int64_t>& dest)
74 {
75     return false;
76 }
77 
AsDoubleVec(std::vector<double> & dest)78 bool EncodedParam::AsDoubleVec(std::vector<double>& dest)
79 {
80     return false;
81 }
82 
AsStringVec(std::vector<std::string> & dest)83 bool EncodedParam::AsStringVec(std::vector<std::string>& dest)
84 {
85     return false;
86 }
87 
Encode()88 bool EncodedParam::Encode()
89 {
90     hasEncoded_ = EncodeKey() && EncodeValueType() && EncodeValue();
91     return hasEncoded_;
92 }
93 
EncodeKey()94 bool EncodedParam::EncodeKey()
95 {
96     if (!RawDataEncoder::StringValueEncoded(rawData_, key_)) {
97         HIVIEW_LOGE("The key of customized value encoded failded.");
98         return false;
99     }
100     return true;
101 }
102 } // namespace EventRaw
103 } // namespace HiviewDFX
104 } // namespace OHOS