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) const19bool 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 if (!parcel.WriteString(timestamp_)) { 31 return false; 32 } 33 if (!parcel.WriteInt32(userId_)) { 34 return false; 35 } 36 return true; 37 }; 38 ReadFromParcel(Parcel & parcel)39bool SecurityEvent::ReadFromParcel(Parcel &parcel) 40 { 41 if (!parcel.ReadInt64(eventId_)) { 42 return false; 43 } 44 if (!parcel.ReadString(version_)) { 45 return false; 46 } 47 if (!parcel.ReadString(content_)) { 48 return false; 49 } 50 if (!parcel.ReadString(timestamp_)) { 51 return false; 52 } 53 if (!parcel.ReadInt32(userId_)) { 54 return false; 55 } 56 return true; 57 }; 58 Unmarshalling(Parcel & parcel)59SecurityEvent* SecurityEvent::Unmarshalling(Parcel &parcel) 60 { 61 SecurityEvent *event = new (std::nothrow) SecurityEvent(); 62 if (event != nullptr && !event->ReadFromParcel(parcel)) { 63 delete event; 64 event = nullptr; 65 } 66 67 return event; 68 }; 69 }