2 #include "ByteBuffer.h"
5 * KeyValue entry for Slot.
6 * @author Brian Demsky <bdemsky@uci.edu>
10 KeyValue::~KeyValue() {
15 KeyValue *KeyValue_decode(ByteBuffer *bb) {
16 int keylength = bb->getInt();
17 int valuelength = bb->getInt();
18 Array<char> *key = new Array<char>(keylength);
21 if (valuelength != 0) {
22 Array<char> *value = new Array<char>(valuelength);
24 return new KeyValue(IoTString_shallow(key), IoTString_shallow(value));
27 return new KeyValue(IoTString_shallow(key), NULL);
30 void KeyValue::encode(ByteBuffer *bb) {
31 bb->putInt(key->length());
33 bb->putInt(value->length());
37 bb->put(key->internalBytes());
39 bb->put(value->internalBytes());
43 int KeyValue::getSize() {
45 return 2 * sizeof(int32_t) + key->length() + value->length();
46 return 2 * sizeof(int32_t) + key->length();
49 KeyValue *KeyValue::getCopy() {
50 return new KeyValue(key->acquireRef(), value->acquireRef());