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 #ifndef IPC_RUST_CXX_PARCEL_H
17 #define IPC_RUST_CXX_PARCEL_H
18 
19 #include <cstddef>
20 #include <cstdint>
21 #include <memory>
22 
23 #include "cxx.h"
24 #include "message_option.h"
25 #include "message_parcel.h"
26 #include "remote_object_wrapper.h"
27 
28 namespace OHOS {
29 
30 namespace IpcRust {
31 
32 std::unique_ptr<MessageParcel> NewMessageParcel();
33 std::unique_ptr<MessageOption> NewMessageOption();
34 
35 Parcel const *AsParcel(const MessageParcel &msgParcel);
36 
37 Parcel *AsParcelMut(MessageParcel &msgParcel);
38 
39 bool WriteInterfaceToken(MessageParcel &msgParcel, const rust::str name);
40 rust::string ReadInterfaceToken(MessageParcel &msgParcel);
41 
42 bool WriteBuffer(MessageParcel &msgParcel, rust::slice<const uint8_t> buffer);
43 bool ReadBuffer(MessageParcel &msgParcel, size_t len, rust::vec<uint8_t> &buffer);
44 
45 bool WriteString(Parcel &parcel, const rust::str val);
46 bool ReadString(Parcel &parcel, rust::string &val);
47 
48 bool WriteString16(Parcel &parcel, const rust::str val);
49 rust::string ReadString16(Parcel &parcel);
50 
51 bool WriteString16Vec(Parcel &parcel, const rust::vec<rust::string &> &v);
52 rust::vec<rust::string> ReadString16Vec(Parcel &parcel);
53 
54 bool WriteBoolVector(Parcel &parcel, rust::slice<const bool> val);
55 bool WriteInt8Vector(Parcel &parcel, rust::slice<const int8_t> val);
56 bool WriteInt16Vector(Parcel &parcel, rust::slice<const int16_t> val);
57 bool WriteInt32Vector(Parcel &parcel, rust::slice<const int32_t> val);
58 bool WriteInt64Vector(Parcel &parcel, rust::slice<const int64_t> val);
59 bool WriteUInt8Vector(Parcel &parcel, rust::slice<const uint8_t> val);
60 bool WriteUInt16Vector(Parcel &parcel, rust::slice<const uint16_t> val);
61 bool WriteUInt32Vector(Parcel &parcel, rust::slice<const uint32_t> val);
62 bool WriteUInt64Vector(Parcel &parcel, rust::slice<const uint64_t> val);
63 bool WriteFloatVector(Parcel &parcel, rust::slice<const float> val);
64 bool WriteDoubleVector(Parcel &parcel, rust::slice<const double> val);
65 bool WriteStringVector(Parcel &parcel, rust::slice<const rust::string> val);
66 bool WriteString16Vector(Parcel &parcel, rust::slice<const rust::string> val);
67 
68 bool ReadBoolVector(Parcel &parcel, rust::vec<bool> &val);
69 bool ReadInt8Vector(Parcel &parcel, rust::vec<int8_t> &val);
70 bool ReadInt16Vector(Parcel &parcel, rust::vec<int16_t> &val);
71 bool ReadInt32Vector(Parcel &parcel, rust::vec<int32_t> &val);
72 bool ReadInt64Vector(Parcel &parcel, rust::vec<int64_t> &val);
73 bool ReadUInt8Vector(Parcel &parcel, rust::vec<uint8_t> &val);
74 bool ReadUInt16Vector(Parcel &parcel, rust::vec<uint16_t> &val);
75 bool ReadUInt32Vector(Parcel &parcel, rust::vec<uint32_t> &val);
76 bool ReadUInt64Vector(Parcel &parcel, rust::vec<uint64_t> &val);
77 bool ReadFloatVector(Parcel &parcel, rust::vec<float> &val);
78 bool ReadDoubleVector(Parcel &parcel, rust::vec<double> &val);
79 bool ReadStringVector(Parcel &parcel, rust::vec<rust::string> &val);
80 bool ReadString16Vector(Parcel &parcel, rust::vec<rust::string> &val);
81 
82 bool WriteRemoteObject(MessageParcel &msgParcel, std::unique_ptr<IRemoteObjectWrapper> object);
83 std::unique_ptr<IRemoteObjectWrapper> ReadRemoteObject(MessageParcel &msgParcel);
84 
85 } // namespace IpcRust
86 } // namespace OHOS
87 
88 #endif
89