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 "string_ex.h"
17#include "report_data.h"
18#include "xcollie_utils.h"
19
20namespace OHOS {
21namespace HiviewDFX {
22bool ReportData::WriteContent(Parcel &parcel) const
23{
24    if (!parcel.WriteBool(forceExit)) {
25        XCOLLIE_LOGE("ForceExit [%{public}s] write bool failed.", forceExit ? "true" : "false");
26        return false;
27    }
28
29    if (!parcel.WriteUint32(state)) {
30        XCOLLIE_LOGE("State [%{public}u] write uint32 failed.", state);
31        return false;
32    }
33
34    if (!parcel.WriteInt32(eventId)) {
35        XCOLLIE_LOGE("EventId [%{public}u] write int32 failed.", eventId);
36        return false;
37    }
38
39    if (token == nullptr) {
40        if (!parcel.WriteBool(false)) {
41            XCOLLIE_LOGE("Token falge [false] write bool failed.");
42            return false;
43        }
44    } else {
45        if (!parcel.WriteBool(true) || !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(token)) {
46            XCOLLIE_LOGE("Token falge [true] write bool failed.");
47            return false;
48        }
49    }
50    return true;
51}
52
53bool ReportData::Marshalling(Parcel &parcel) const
54{
55    if (!parcel.WriteString(errorObject.name)) {
56        XCOLLIE_LOGE("Name [%{public}s] write string failed.", errorObject.name.c_str());
57        return false;
58    }
59
60    if (!parcel.WriteString(errorObject.message)) {
61        XCOLLIE_LOGE("Message [%{public}s] write string failed.", errorObject.message.c_str());
62        return false;
63    }
64
65    if (!parcel.WriteString(errorObject.stack)) {
66        XCOLLIE_LOGE("Stack [%{public}s] write string failed.", errorObject.stack.c_str());
67        return false;
68    }
69
70    if (!parcel.WriteInt32(static_cast<int32_t>(faultType))) {
71        XCOLLIE_LOGE("FaultType [%{public}d] write int32 failed.", static_cast<int32_t>(faultType));
72        return false;
73    }
74
75    if (!parcel.WriteString(timeoutMarkers)) {
76        XCOLLIE_LOGE("TimeoutMarkers [%{public}s] write string failed.", timeoutMarkers.c_str());
77        return false;
78    }
79
80    if (!parcel.WriteBool(waitSaveState)) {
81        XCOLLIE_LOGE("WaitSaveState [%{public}s] write bool failed.", waitSaveState ? "true" : "false");
82        return false;
83    }
84
85    if (!parcel.WriteBool(notifyApp)) {
86        XCOLLIE_LOGE("NotifyApp [%{public}s] write bool failed.", notifyApp ? "true" : "false");
87        return false;
88    }
89
90    return WriteContent(parcel);
91}
92} // end of HiviewDFX
93} // end of OHOS
94