1 /*
2 * Copyright (c) 2021-2024 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 "subscribe_info.h"
17
18 #include <initializer_list>
19 #include <iosfwd>
20 #include <map>
21 #include <nlohmann/json.hpp>
22 #include <string>
23 #include <type_traits>
24 #include <vector>
25
26 #include "device_profile_log.h"
27 #include "device_profile_utils.h"
28 #include "parcel.h"
29 #include "parcel_helper.h"
30 #include "profile_event.h"
31
32 namespace OHOS {
33 namespace DeviceProfile {
34 namespace {
35 const std::string TAG = "SubscribeInfo";
36 }
37
Marshalling(Parcel & parcel) const38 bool SubscribeInfo::Marshalling(Parcel& parcel) const
39 {
40 PARCEL_WRITE_HELPER_RET(parcel, Uint32, profileEvent, false);
41 PARCEL_WRITE_HELPER_RET(parcel, String, extraInfo.dump(), false);
42 return true;
43 }
44
Unmarshalling(Parcel & parcel)45 bool SubscribeInfo::Unmarshalling(Parcel& parcel)
46 {
47 profileEvent = static_cast<ProfileEvent>(parcel.ReadUint32());
48 if (profileEvent >= EVENT_PROFILE_END || profileEvent == EVENT_UNKNOWN) {
49 HILOGE("invalid profile event, %{public}u", static_cast<uint32_t>(profileEvent));
50 return false;
51 }
52 std::string value = parcel.ReadString();
53 extraInfo = ExtraInfo::parse(value, nullptr, false);
54 if (extraInfo.is_discarded()) {
55 HILOGE("parse extra info failed, %{public}s", DeviceProfileUtils::AnonymizeString(value).c_str());
56 return false;
57 }
58 return true;
59 }
60
operator !=(const SubscribeInfo & rhs) const61 bool SubscribeInfo::operator!=(const SubscribeInfo& rhs) const
62 {
63 return ((profileEvent != rhs.profileEvent) || (extraInfo != rhs.extraInfo));
64 }
65 } // namespace DeviceProfile
66 } // namespace OHOS
67