1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 OHOS_INTER_IPC_CODEC_BIND_MARCROS_H 17 #define OHOS_INTER_IPC_CODEC_BIND_MARCROS_H 18 19 #include "ipc_codec.h" 20 21 namespace OHOS { 22 namespace Sharing { 23 24 #define IPC_BIND_ATTR0 \ 25 int32_t IpcSerialize(MessageParcel &pacel) \ 26 { \ 27 return 0; \ 28 } \ 29 int32_t IpcDeserialize(MessageParcel &pacel) \ 30 { \ 31 return 0; \ 32 } 33 34 #define IPC_BIND_ATTR(...) \ 35 int32_t IpcSerialize(MessageParcel &pacel) \ 36 { \ 37 return IpcSerialize(pacel, __VA_ARGS__); \ 38 } \ 39 template <class T, class... Args> \ 40 int32_t IpcSerialize(MessageParcel &pacel, T first, Args... last) \ 41 { \ 42 if (!IPC_CODEC::IpcEncodeBindAttr(pacel, first)) { \ 43 return -1; \ 44 } \ 45 return IpcSerialize(pacel, last...); \ 46 } \ 47 template <class T> \ 48 int32_t IpcSerialize(MessageParcel &pacel, T t) \ 49 { \ 50 if (!IPC_CODEC::IpcEncodeBindAttr(pacel, t)) { \ 51 return -1; \ 52 } \ 53 return 0; \ 54 } \ 55 \ 56 int32_t IpcDeserialize(MessageParcel &pacel) \ 57 { \ 58 return IpcDeserialize(pacel, __VA_ARGS__); \ 59 } \ 60 template <class T, class... Args> \ 61 int32_t IpcDeserialize(MessageParcel &pacel, T &first, Args &...last) \ 62 { \ 63 if (!IPC_CODEC::IpcDecodeBindAttr(pacel, first)) { \ 64 return -1; \ 65 } \ 66 return IpcDeserialize(pacel, last...); \ 67 } \ 68 template <class T> \ 69 int32_t IpcDeserialize(MessageParcel &pacel, T &t) \ 70 { \ 71 if (!IPC_CODEC::IpcDecodeBindAttr(pacel, t)) { \ 72 return -1; \ 73 } \ 74 return 0; \ 75 } 76 77 } // namespace Sharing 78 } // namespace OHOS 79 80 #endif 81