2 #include "ByteBuffer.h"
5 * KeyValue entry for Slot.
6 * @author Brian Demsky <bdemsky@uci.edu>
10 KeyValue *KeyValue_decode(ByteBuffer *bb) {
11 int keylength = bb->getInt();
12 int valuelength = bb->getInt();
13 Array<char> *key = new Array<char>(keylength);
16 if (valuelength != 0) {
17 Array<char> *value = new Array<char>(valuelength);
19 return new KeyValue(IoTString_shallow(key), IoTString_shallow(value));
22 return new KeyValue(IoTString_shallow(key), NULL);
25 void KeyValue::encode(ByteBuffer *bb) {
26 bb->putInt(key->length());
29 bb->putInt(value->length());
34 bb->put(key->internalBytes());
37 bb->put(value->internalBytes());
41 int KeyValue::getSize() {
43 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, value);