From: Junghoon Park Date: Tue, 12 Nov 2019 23:44:13 +0000 (+0900) Subject: Add internal APIs for parcel X-Git-Tag: submit/tizen/20191113.041200~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1d896e69b4de9faad0bb8ff9576c9b52c2afaa90;p=platform%2Fcore%2Fappfw%2Frpc-port.git Add internal APIs for parcel - int rpc_port_parcel_reset_reader(rpc_port_parcel_h h); - int rpc_port_parcel_to_array(rpc_port_parcel_h h, void **array, unsigned int *size); - int rpc_port_parcel_from_array(rpc_port_parcel_h h, const void *array, unsigned int size); Change-Id: I62b659cb2c8b79e9f566303352dbb619ffd47300 Signed-off-by: Junghoon Park --- diff --git a/src/parcel-internal.cc b/src/parcel-internal.cc index 3fce740..54f2d99 100644 --- a/src/parcel-internal.cc +++ b/src/parcel-internal.cc @@ -151,4 +151,18 @@ void Parcel::Read(unsigned char* buf, unsigned int size) { reader_ += size; } +void Parcel::ResetReader() { + reader_ = 0; +} + +void Parcel::Clear() { + data_.clear(); + reader_ = 0; +} + +void Parcel::Reset(const unsigned char* buf, unsigned int size) { + Clear(); + Write(buf, size); +} + } // namespace rpc_port diff --git a/src/parcel-internal.h b/src/parcel-internal.h index ac2290a..991fe17 100644 --- a/src/parcel-internal.h +++ b/src/parcel-internal.h @@ -54,6 +54,9 @@ class Parcel { bundle* ReadBundle(); int ReadArrayCount(); const std::vector& GetRaw(); + void ResetReader(); + void Clear(); + void Reset(const unsigned char* buf, unsigned int size); private: template diff --git a/src/rpc-port-parcel.cc b/src/rpc-port-parcel.cc index 55c10b2..8ce15d3 100644 --- a/src/rpc-port-parcel.cc +++ b/src/rpc-port-parcel.cc @@ -376,3 +376,45 @@ RPC_API int rpc_port_parcel_burst_write(rpc_port_parcel_h h, return RPC_PORT_ERROR_NONE; } + +RPC_API int rpc_port_parcel_reset_reader(rpc_port_parcel_h h) { + if (h == nullptr) + return RPC_PORT_ERROR_INVALID_PARAMETER; + + Parcel* p = static_cast(h); + + p->ResetReader(); + + return RPC_PORT_ERROR_NONE; +} + +RPC_API int rpc_port_parcel_to_array(rpc_port_parcel_h h, void **array, + unsigned int *size) { + if (h == nullptr || !array || !size) + return RPC_PORT_ERROR_INVALID_PARAMETER; + + Parcel* p = static_cast(h); + + const auto& ptr = p->GetRaw(); + void* array_ptr = malloc(ptr.size()); + if (!array_ptr) + return RPC_PORT_ERROR_OUT_OF_MEMORY; + + memcpy(array_ptr, ptr.data(), ptr.size()); + *array = array_ptr; + *size = ptr.size(); + + return RPC_PORT_ERROR_NONE; +} + +RPC_API int rpc_port_parcel_from_array(rpc_port_parcel_h h, const void *array, + unsigned int size) { + if (h == nullptr || !array || size == 0) + return RPC_PORT_ERROR_INVALID_PARAMETER; + + Parcel* p = static_cast(h); + + p->Reset(reinterpret_cast(array), size); + + return RPC_PORT_ERROR_NONE; +} \ No newline at end of file