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#ifndef HDI_PARCEL_UTILS_V1_0_H
17#define HDI_PARCEL_UTILS_V1_0_H
18
19#include <message_parcel.h>
20#include "hdf_sbuf_ipc.h"
21#include "display_type.h"
22#include "hdf_log.h"
23
24namespace OHOS {
25namespace HDI {
26namespace Display {
27namespace V1_0 {
28class ParcelUtils {
29public:
30    static int32_t UnpackAllocInfo(MessageParcel &data, AllocInfo *pAllocInfo)
31    {
32        if (pAllocInfo == nullptr) {
33            return DISPLAY_NULL_PTR;
34        }
35        pAllocInfo->width  = data.ReadUint32();
36        pAllocInfo->height = data.ReadUint32();
37        pAllocInfo->usage  = data.ReadUint64();
38        pAllocInfo->format = static_cast<PixelFormat>(data.ReadUint32());
39        pAllocInfo->expectedSize = data.ReadUint32();
40        return DISPLAY_SUCCESS;
41    }
42
43    static int32_t PackAllocInfo(MessageParcel &data, const AllocInfo *pAllocInfo)
44    {
45        if (pAllocInfo == nullptr) {
46            return DISPLAY_NULL_PTR;
47        }
48        if (!data.WriteUint32(pAllocInfo->width)) {
49            HDF_LOGE("%{public}s: write AllocInfo width failed", __func__);
50            return DISPLAY_PARAM_ERR;
51        }
52        if (!data.WriteUint32(pAllocInfo->height)) {
53            HDF_LOGE("%{public}s: write AllocInfo height failed", __func__);
54            return DISPLAY_PARAM_ERR;
55        }
56        if (!data.WriteUint64(pAllocInfo->usage)) {
57            HDF_LOGE("%{public}s: write AllocInfo usage failed", __func__);
58            return DISPLAY_PARAM_ERR;
59        }
60        if (!data.WriteUint32(pAllocInfo->format)) {
61            HDF_LOGE("%{public}s: write AllocInfo format failed", __func__);
62            return DISPLAY_PARAM_ERR;
63        }
64        if (!data.WriteUint32(pAllocInfo->expectedSize)) {
65            HDF_LOGE("%{public}s: write AllocInfo type failed", __func__);
66            return DISPLAY_PARAM_ERR;
67        }
68        return DISPLAY_SUCCESS;
69    }
70};
71} // namespace V1_0
72} // namespace Display
73} // namespace HDI
74} // namespace OHOS
75
76#endif // HDI_PARCEL_UTILS_V1_0_H
77