IoT - Kubus / Mbed 2 deprecated Kubus

Dependencies:   mbed nRF24L01P

Revision:
8:1861d0eef60a
Parent:
2:6541a391bdbd
Child:
37:1251e35fe43e
Child:
40:40d4161fe1ad
diff -r e51d0fbb1a25 -r 1861d0eef60a common.cpp
--- a/common.cpp	Thu Jan 05 13:13:28 2017 +0000
+++ b/common.cpp	Thu Jan 05 13:23:49 2017 +0100
@@ -1,11 +1,20 @@
 #include "common.h"
+#include <cstring>
 
 std::string Data::serialize() {
     std::string serialized;
     serialized.push_back(type);
-    serialized.push_back(counter);
+    serialized.append((char*)&value, sizeof(value));
     return serialized;
 };
+bool Data::deserialize(std::string str) {
+    if(str.length() < 1 + sizeof(value)) {
+        return false;
+    }
+    type = str[0];
+    memcpy(&value, str.data() + 1, sizeof(value));
+    return true;
+}
 
 void radio_init(nRF24L01P* radio, unsigned long long rx_address,
         unsigned long long tx_address) {