Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Tizen.Applications.Common/Interop/Interop.RPCPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ internal static partial class Parcel
[DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_create_without_header")]
internal static extern ErrorCode CreateWithoutHeader(out IntPtr parcelHandle);

//int rpc_port_parcel_create_with_capacity(rpc_port_parcel_h* h, size_t capacity);
[DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_create_with_capacity")]
internal static extern ErrorCode CreateWithCapacity(out IntPtr parcelHandle, UIntPtr capacity);

//int rpc_port_parcel_reserve(rpc_port_parcel_h h, unsigned int size);
[DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_reserve")]
internal static extern ErrorCode Reserve(IntPtr parcelHandle, uint size);
Expand Down Expand Up @@ -215,6 +219,10 @@ internal static partial class Parcel
//int rpc_port_parcel_create_from_parcel(rpc_port_parcel_h* h, rpc_port_parcel_h origin_parcel, unsigned int start_pos, unsigned int size);
[DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_create_from_parcel")]
internal static extern ErrorCode CreateFromParcel(out IntPtr parcelHandle, IntPtr originParcel, uint startPos, uint size);

//int rpc_port_parcel_get_data_ptr(rpc_port_parcel_h h, unsigned char** ptr)
[DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_get_data_ptr")]
internal static extern ErrorCode GetDataPtr(IntPtr parcelHandle, out IntPtr dataHandle);
}

internal static partial class Proxy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.ComponentModel;
using System.Reflection.Metadata;
using System.Runtime.InteropServices;
using System.Text;

namespace Tizen.Applications.RPCPort
{
Expand Down Expand Up @@ -201,6 +202,22 @@ public Parcel(Parcel origin, uint startPos, uint size)
throw new InvalidIOException();
}

/// <summary>
/// Constructs with capacity.
/// </summary>
/// <param name="capacity">The size of the new parcel.</param>
/// <exception cref="InvalidIOException">Thrown when an internal IO error occurs.</exception>
/// <since_tizen> 11 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public Parcel(uint capacity)
{
Interop.LibRPCPort.ErrorCode error;

error = Interop.LibRPCPort.Parcel.CreateWithCapacity(out _handle, capacity);
if (error != Interop.LibRPCPort.ErrorCode.None)
throw new InvalidIOException();
}

/// <summary>
/// Constructs a new instance of the Parcel class.
/// </summary>
Expand Down Expand Up @@ -422,7 +439,23 @@ public void WriteDouble(double b)
/// <since_tizen> 5 </since_tizen>
public void WriteString(string b)
{
Interop.LibRPCPort.Parcel.WriteString(_handle, b);
int utf8ByteCount = Encoding.UTF8.GetByteCount(b);
Interop.LibRPCPort.Parcel.WriteInt32(_handle, utf8ByteCount + 1);
Interop.LibRPCPort.Parcel.GetDataSize(_handle, out uint size);
Interop.LibRPCPort.Parcel.Reserve(_handle, (uint)utf8ByteCount + 1);
Interop.LibRPCPort.Parcel.GetDataPtr(_handle, out IntPtr dataHandle);

unsafe
{
fixed (char* charPtr = b)
{
byte* bytePtr = (byte*)dataHandle.ToPointer() + size;
int bytesEncoded = Encoding.UTF8.GetBytes(
charPtr, b.Length,
bytePtr, utf8ByteCount);
bytePtr[bytesEncoded] = 0;
}
}
}

/// <summary>
Expand Down
Loading