• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "faultlog_info_ohos.h"
16 
17 #include "parcel.h"
18 
19 namespace OHOS {
20 namespace HiviewDFX {
Marshalling(Parcel & parcel) const21 bool FaultLogInfoOhos::Marshalling(Parcel& parcel) const
22 {
23     if (!parcel.WriteInt64(time)) {
24         return false;
25     }
26 
27     if (!parcel.WriteInt32(uid)) {
28         return false;
29     }
30 
31     if (!parcel.WriteInt32(pid)) {
32         return false;
33     }
34 
35     if (!parcel.WriteInt32(faultLogType)) {
36         return false;
37     }
38 
39     if (!parcel.WriteString(module)) {
40         return false;
41     }
42 
43     if (!parcel.WriteString(reason)) {
44         return false;
45     }
46 
47     if (!parcel.WriteString(summary)) {
48         return false;
49     }
50 
51     if (!parcel.WriteString(logPath)) {
52         return false;
53     }
54 
55     uint32_t size = sectionMaps.size();
56     if (!parcel.WriteUint32(size)) {
57         return false;
58     }
59 
60     for (const auto [key, value] : sectionMaps) {
61         if (!parcel.WriteString(key)) {
62             return false;
63         }
64 
65         if (!parcel.WriteString(value)) {
66             return false;
67         }
68     }
69     return true;
70 }
71 
Unmarshalling(Parcel & parcel)72 FaultLogInfoOhos* FaultLogInfoOhos::Unmarshalling(Parcel& parcel)
73 {
74     const uint32_t maxSize = 128;
75     uint32_t size;
76     uint32_t i;
77     FaultLogInfoOhos* ret = new FaultLogInfoOhos();
78     if (!parcel.ReadInt64(ret->time)) {
79         goto error;
80     }
81 
82     if (!parcel.ReadInt32(ret->uid)) {
83         goto error;
84     }
85 
86     if (!parcel.ReadInt32(ret->pid)) {
87         goto error;
88     }
89 
90     if (!parcel.ReadInt32(ret->faultLogType)) {
91         goto error;
92     }
93 
94     if (!parcel.ReadString(ret->module)) {
95         goto error;
96     }
97 
98     if (!parcel.ReadString(ret->reason)) {
99         goto error;
100     }
101 
102     if (!parcel.ReadString(ret->summary)) {
103         goto error;
104     }
105 
106     if (!parcel.ReadString(ret->logPath)) {
107         goto error;
108     }
109 
110     if (!parcel.ReadUint32(size)) {
111         goto error;
112     }
113 
114     if (size > maxSize) {
115         goto error;
116     }
117 
118     for (i = 0; i < size; i++) {
119         std::string key;
120         std::string value;
121         if (!parcel.ReadString(key)) {
122             goto error;
123         }
124 
125         if (!parcel.ReadString(value)) {
126             goto error;
127         }
128 
129         ret->sectionMaps[key] = value;
130     }
131     return ret;
132 
133 error:
134     delete ret;
135     ret = nullptr;
136     return nullptr;
137 }
138 }  // namespace hiview
139 }  // namespace OHOS
140