more edits
[iotcloud.git] / version2 / src / C / NewKey.cc
index 745f22d977d31d072ff9dc35b4a5a44147e9cfdd..85a5234a94b58b4af202534a42a394deb7a63efe 100644 (file)
@@ -1,59 +1,22 @@
+#include "NewKey.h"
+#include "ByteBuffer.h"
+
+Entry * decode(Slot * slot, ByteBuffer * bb) {
+       int keylength = bb->getInt();
+       Array<char> * key = new Array<char>(keylength);
+       bb->get(key);
+       int64_t machineid = bb->getLong();
+       
+       return new NewKey(slot, IoTString.shallow(key), machineid);
+}
 
+void NewKey::encode(ByteBuffer * bb) {
+       bb->put(TypeNewKey);
+       bb->putInt(key->length());
+       bb->put(key->internalBytes());
+       bb->putLong(machineid);
+}
 
-/**
- * This Entry records the abort sent by a given machine.
- * @author Ali Younis <ayounis@uci.edu>
- * @version 1.0
- */
-
-
-class NewKey extends Entry {
-       IoTString key;
-       int64_t machineid;
-
-       NewKey(Slot slot, IoTString _key, int64_t _machineid) {
-               super(slot);
-               key = _key;
-               machineid = _machineid;
-       }
-
-       int64_t getMachineID() {
-               return machineid;
-       }
-
-       IoTString getKey() {
-               return key;
-       }
-
-       void setSlot(Slot s) {
-               parentslot = s;
-       }
-
-       static Entry decode(Slot slot, ByteBuffer bb) {
-               int keylength = bb.getInt();
-               char[] key = new char[keylength];
-               bb.get(key);
-               int64_t machineid = bb.getLong();
-
-               return new NewKey(slot, IoTString.shallow(key), machineid);
-       }
-
-       void encode(ByteBuffer bb) {
-               bb.put(Entry.TypeNewKey);
-               bb.putInt(key.length());
-               bb.put(key.internalBytes());
-               bb.putLong(machineid);
-       }
-
-       int getSize() {
-               return sizeof(int64_t) + sizeof(char) + sizeof(int32_t) + key.length();
-       }
-
-       char getType() {
-               return Entry.TypeNewKey;
-       }
-
-       Entry getCopy(Slot s) {
-               return new NewKey(s, key, machineid);
-       }
+int NewKey::getSize() {
+       return sizeof(int64_t) + sizeof(char) + sizeof(int32_t) + key.length();
 }