Bug 542052: Add support for serializing/deserializing byte types. r=bent
--- a/ipc/glue/IPCMessageUtils.h
+++ b/ipc/glue/IPCMessageUtils.h
@@ -46,16 +46,58 @@
#include "nsTArray.h"
#ifdef _MSC_VER
#pragma warning( disable : 4800 )
#endif
namespace IPC {
+template<>
+struct ParamTraits<PRInt8>
+{
+ typedef PRInt8 paramType;
+
+ static void Write(Message* aMsg, const paramType& aParam)
+ {
+ aMsg->WriteBytes(&aParam, sizeof(aParam));
+ }
+
+ static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
+ {
+ const char* outp;
+ if (!aMsg->ReadBytes(aIter, &outp, sizeof(*aResult)))
+ return false;
+
+ *aResult = *reinterpret_cast<const paramType*>(outp);
+ return true;
+ }
+};
+
+template<>
+struct ParamTraits<PRUint8>
+{
+ typedef PRUint8 paramType;
+
+ static void Write(Message* aMsg, const paramType& aParam)
+ {
+ aMsg->WriteBytes(&aParam, sizeof(aParam));
+ }
+
+ static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
+ {
+ const char* outp;
+ if (!aMsg->ReadBytes(aIter, &outp, sizeof(*aResult)))
+ return false;
+
+ *aResult = *reinterpret_cast<const paramType*>(outp);
+ return true;
+ }
+};
+
template <>
struct ParamTraits<nsACString>
{
typedef nsACString paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
bool isVoid = aParam.IsVoid();
--- a/ipc/ipdl/test/cxx/PTestSanity.ipdl
+++ b/ipc/ipdl/test/cxx/PTestSanity.ipdl
@@ -1,21 +1,21 @@
namespace mozilla {
namespace _ipdltest {
protocol PTestSanity {
child:
- Ping(int zero, float zeroPtFive);
+ Ping(int zero, float zeroPtFive, int8_t dummy);
__delete__();
parent:
- Pong(int one, float zeroPtTwoFive);
+ Pong(int one, float zeroPtTwoFive, uint8_t dummy);
state PING:
send Ping goto PONG;
state PONG:
recv Pong goto DEAD;
--- a/ipc/ipdl/test/cxx/TestSanity.cpp
+++ b/ipc/ipdl/test/cxx/TestSanity.cpp
@@ -16,23 +16,24 @@ TestSanityParent::TestSanityParent()
TestSanityParent::~TestSanityParent()
{
MOZ_COUNT_DTOR(TestSanityParent);
}
void
TestSanityParent::Main()
{
- if (!SendPing(0, 0.5f))
+ if (!SendPing(0, 0.5f, 0))
fail("sending Ping");
}
bool
-TestSanityParent::RecvPong(const int& one, const float& zeroPtTwoFive)
+TestSanityParent::RecvPong(const int& one, const float& zeroPtTwoFive,
+ const uint8_t&/*unused*/)
{
if (1 != one)
fail("invalid argument `%d', should have been `1'", one);
if (0.25f != zeroPtTwoFive)
fail("invalid argument `%g', should have been `0.25'", zeroPtTwoFive);
Close();
@@ -50,24 +51,25 @@ TestSanityChild::TestSanityChild()
}
TestSanityChild::~TestSanityChild()
{
MOZ_COUNT_DTOR(TestSanityChild);
}
bool
-TestSanityChild::RecvPing(const int& zero, const float& zeroPtFive)
+TestSanityChild::RecvPing(const int& zero, const float& zeroPtFive,
+ const int8_t&/*unused*/)
{
if (0 != zero)
fail("invalid argument `%d', should have been `0'", zero);
if (0.5f != zeroPtFive)
fail("invalid argument `%g', should have been `0.5'", zeroPtFive);
- if (!SendPong(1, 0.25f))
+ if (!SendPong(1, 0.25f, 0))
fail("sending Pong");
return true;
}
} // namespace _ipdltest
} // namespace mozilla
--- a/ipc/ipdl/test/cxx/TestSanity.h
+++ b/ipc/ipdl/test/cxx/TestSanity.h
@@ -16,17 +16,18 @@ class TestSanityParent :
public:
TestSanityParent();
virtual ~TestSanityParent();
void Main();
protected:
NS_OVERRIDE
- virtual bool RecvPong(const int& one, const float& zeroPtTwoFive);
+ virtual bool RecvPong(const int& one, const float& zeroPtTwoFive,
+ const uint8_t& dummy);
NS_OVERRIDE
virtual void ActorDestroy(ActorDestroyReason why)
{
if (NormalShutdown != why)
fail("unexpected destruction!");
passed("ok");
QuitParent();
@@ -38,17 +39,18 @@ class TestSanityChild :
public PTestSanityChild
{
public:
TestSanityChild();
virtual ~TestSanityChild();
protected:
NS_OVERRIDE
- virtual bool RecvPing(const int& zero, const float& zeroPtFive);
+ virtual bool RecvPing(const int& zero, const float& zeroPtFive,
+ const int8_t& dummy);
NS_OVERRIDE
virtual void ActorDestroy(ActorDestroyReason why)
{
if (NormalShutdown != why)
fail("unexpected destruction!");
QuitChild();
}