From 3a35f019a647a021adcbe9971d38eb11f543d585 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Thu, 4 Feb 2016 12:35:13 +0100 Subject: [PATCH] Bug 1194721: Add additional PDU pack and unpack functions, r=shuang This patch adds PDU pack and unpack functions for 64-bit integer values and floating-point values. --- ipc/hal/DaemonSocketPDUHelpers.h | 48 ++++++++++++++++++++++++++++++++ ipc/unixsocket/SocketBase.h | 40 ++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/ipc/hal/DaemonSocketPDUHelpers.h b/ipc/hal/DaemonSocketPDUHelpers.h index 3c9fb775e87..219a0ce0198 100644 --- a/ipc/hal/DaemonSocketPDUHelpers.h +++ b/ipc/hal/DaemonSocketPDUHelpers.h @@ -188,6 +188,30 @@ PackPDU(uint32_t aIn, DaemonSocketPDU& aPDU) return aPDU.Write(aIn); } +inline nsresult +PackPDU(int64_t aIn, DaemonSocketPDU& aPDU) +{ + return aPDU.Write(aIn); +} + +inline nsresult +PackPDU(uint64_t aIn, DaemonSocketPDU& aPDU) +{ + return aPDU.Write(aIn); +} + +inline nsresult +PackPDU(float aIn, DaemonSocketPDU& aPDU) +{ + return aPDU.Write(aIn); +} + +inline nsresult +PackPDU(double aIn, DaemonSocketPDU& aPDU) +{ + return aPDU.Write(aIn); +} + nsresult PackPDU(const DaemonSocketPDUHeader& aIn, DaemonSocketPDU& aPDU); @@ -646,6 +670,30 @@ UnpackPDU(DaemonSocketPDU& aPDU, uint32_t& aOut) return aPDU.Read(aOut); } +inline nsresult +UnpackPDU(DaemonSocketPDU& aPDU, int64_t& aOut) +{ + return aPDU.Read(aOut); +} + +inline nsresult +UnpackPDU(DaemonSocketPDU& aPDU, uint64_t& aOut) +{ + return aPDU.Read(aOut); +} + +inline nsresult +UnpackPDU(DaemonSocketPDU& aPDU, float& aOut) +{ + return aPDU.Read(aOut); +} + +inline nsresult +UnpackPDU(DaemonSocketPDU& aPDU, double& aOut) +{ + return aPDU.Read(aOut); +} + inline nsresult UnpackPDU(DaemonSocketPDU& aPDU, DaemonSocketPDUHeader& aOut) { diff --git a/ipc/unixsocket/SocketBase.h b/ipc/unixsocket/SocketBase.h index e59d4dea14f..65d912cefd7 100644 --- a/ipc/unixsocket/SocketBase.h +++ b/ipc/unixsocket/SocketBase.h @@ -73,6 +73,26 @@ public: return Read(&aValue, sizeof(aValue)); } + nsresult Read(int64_t& aValue) + { + return Read(&aValue, sizeof(aValue)); + } + + nsresult Read(uint64_t& aValue) + { + return Read(&aValue, sizeof(aValue)); + } + + nsresult Read(float& aValue) + { + return Read(&aValue, sizeof(aValue)); + } + + nsresult Read(double& aValue) + { + return Read(&aValue, sizeof(aValue)); + } + uint8_t* Append(size_t aLen); nsresult Write(const void* aValue, size_t aLen); @@ -107,6 +127,26 @@ public: return Write(&aValue, sizeof(aValue)); } + nsresult Write(int64_t aValue) + { + return Write(&aValue, sizeof(aValue)); + } + + nsresult Write(uint64_t aValue) + { + return Write(&aValue, sizeof(aValue)); + } + + nsresult Write(float aValue) + { + return Write(&aValue, sizeof(aValue)); + } + + nsresult Write(double aValue) + { + return Write(&aValue, sizeof(aValue)); + } + protected: UnixSocketBuffer();