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 "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 "parcel.h"
28 #include "parcel_helper.h"
29 #include "profile_event.h"
30
31 namespace OHOS {
32 namespace DeviceProfile {
33 namespace {
34 const std::string TAG = "SubscribeInfo";
35 }
36
Marshalling(Parcel & parcel) const37 bool SubscribeInfo::Marshalling(Parcel& parcel) const
38 {
39 PARCEL_WRITE_HELPER_RET(parcel, Uint32, profileEvent, false);
40 PARCEL_WRITE_HELPER_RET(parcel, String, extraInfo.dump(), false);
41 return true;
42 }
43
Unmarshalling(Parcel & parcel)44 bool SubscribeInfo::Unmarshalling(Parcel& parcel)
45 {
46 profileEvent = static_cast<ProfileEvent>(parcel.ReadUint32());
47 if (profileEvent >= EVENT_PROFILE_END || profileEvent == EVENT_UNKNOWN) {
48 HILOGE("invalid profile event, %{public}d", profileEvent);
49 return false;
50 }
51 std::string value = parcel.ReadString();
52 extraInfo = ExtraInfo::parse(value, nullptr, false);
53 if (extraInfo.is_discarded()) {
54 HILOGE("parse extra info failed, %{public}s", value.c_str());
55 return false;
56 }
57 return true;
58 }
59
operator !=(const SubscribeInfo & rhs) const60 bool SubscribeInfo::operator!=(const SubscribeInfo& rhs) const
61 {
62 return ((profileEvent != rhs.profileEvent) || (extraInfo != rhs.extraInfo));
63 }
64 } // namespace DeviceProfile
65 } // namespace OHOS