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