1 /*
2  * Copyright (c) 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 "security_event.h"
17 
18 namespace OHOS::Security::SecurityCollector {
Marshalling(Parcel & parcel) const19 bool SecurityEvent::Marshalling(Parcel& parcel) const
20 {
21     if (!parcel.WriteInt64(eventId_)) {
22         return false;
23     }
24     if (!parcel.WriteString(version_)) {
25         return false;
26     }
27     if (!parcel.WriteString(content_)) {
28         return false;
29     }
30     return true;
31 };
32 
ReadFromParcel(Parcel & parcel)33 bool SecurityEvent::ReadFromParcel(Parcel &parcel)
34 {
35     if (!parcel.ReadInt64(eventId_)) {
36         return false;
37     }
38     if (!parcel.ReadString(version_)) {
39         return false;
40     }
41     if (!parcel.ReadString(content_)) {
42         return false;
43     }
44     return true;
45 };
46 
Unmarshalling(Parcel & parcel)47 SecurityEvent* SecurityEvent::Unmarshalling(Parcel &parcel)
48 {
49     SecurityEvent *event = new (std::nothrow) SecurityEvent();
50     if (event != nullptr && !event->ReadFromParcel(parcel)) {
51         delete event;
52         event = nullptr;
53     }
54 
55     return event;
56 };
57 }