edits
[iotcloud.git] / version2 / src / C / KeyValue.cc
index a906de5e45d3307193a398bdf94236abb05337f4..96d740d9bfeb3cffc217eb215999ed4e2d11e7a7 100644 (file)
@@ -1,74 +1,51 @@
-
+#include "KeyValue.h"
+#include "ByteBuffer.h"
+#include "IoTString.h"
 /**
  * KeyValue entry for Slot.
  * @author Brian Demsky <bdemsky@uci.edu>
  * @version 1.0
  */
 
-class KeyValue { /*extends Entry */
-       IoTString key;
-       IoTString value;
-
-       KeyValue(IoTString _key, IoTString _value) {
-               key = _key;
-               value = _value;
-       }
+KeyValue *KeyValue_decode(ByteBuffer *bb) {
+       int keylength = bb->getInt();
+       int valuelength = bb->getInt();
+       Array<char> *key = new Array<char>(keylength);
+       bb->get(key);
 
-       IoTString getKey() {
-               return key;
+       if (valuelength != 0) {
+               Array<char> *value = new Array<char>(valuelength);
+               bb->get(value);
+               return new KeyValue(IoTString_shallow(key), IoTString_shallow(value));
        }
 
-       IoTString getValue() {
-               return value;
-       }
-
-       static KeyValue decode(ByteBuffer bb) {
-               int keylength = bb.getInt();
-               int valuelength = bb.getInt();
-               char[] key = new char[keylength];
-               bb.get(key);
+       return new KeyValue(IoTString_shallow(key), NULL);
+}
 
-               if (valuelength != 0) {
-                       char[] value = new char[valuelength];
-                       bb.get(value);
-                       return new KeyValue(IoTString.shallow(key), IoTString.shallow(value));
-               }
+void KeyValue::encode(ByteBuffer *bb) {
+       bb->putInt(key->length());
 
-               return new KeyValue(IoTString.shallow(key), NULL);
+       if (value != NULL) {
+               bb->putInt(value->length());
+       } else {
+               bb->putInt(0);
        }
 
-       void encode(ByteBuffer bb) {
-               bb.putInt(key.length());
-
-               if (value != NULL) {
-                       bb.putInt(value.length());
-               } else {
-                       bb.putInt(0);
-               }
+       bb->put(key->internalBytes());
 
-               bb.put(key.internalBytes());
-
-               if (value != NULL) {
-                       bb.put(value.internalBytes());
-               }
+       if (value != NULL) {
+               bb->put(value->internalBytes());
        }
+}
 
-       int getSize() {
-               if (value != NULL) {
-                       return 2 * sizeof(int32_t) + key.length() + value.length();
-               }
-
-               return 2 * sizeof(int32_t) + key.length();
+int KeyValue::getSize() {
+       if (value != NULL) {
+               return 2 * sizeof(int32_t) + key->length() + value->length();
        }
 
-       String toString() {
-               if (value == NULL) {
-                       return "NULL";
-               }
-               return value.toString();
-       }
+       return 2 * sizeof(int32_t) + key->length();
+}
 
-       KeyValue getCopy() {
-               return new KeyValue(key, value);
-       }
+KeyValue *KeyValue::getCopy() {
+       return new KeyValue(key, value);
 }