Bug 542052: Add support for serializing/deserializing byte types. r=bent
authorChris Jones <jones.chris.g@gmail.com>
Mon, 25 Jan 2010 16:47:39 -0600
changeset 37495 6b4e8bbbfe3a8221d8283105777aef9ac421d769
parent 37494 bee5caea0941c7f3958c30a90abdae07935cc230
child 37496 cd5868a825d86e29e495e5452421660893078858
push id11338
push usercjones@mozilla.com
push dateMon, 25 Jan 2010 22:49:41 +0000
treeherdermozilla-central@6b4e8bbbfe3a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs542052
milestone1.9.3a1pre
Bug 542052: Add support for serializing/deserializing byte types. r=bent
ipc/glue/IPCMessageUtils.h
ipc/ipdl/test/cxx/PTestSanity.ipdl
ipc/ipdl/test/cxx/TestSanity.cpp
ipc/ipdl/test/cxx/TestSanity.h
--- 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();
     }