Adding Fidelius manual.
[iotcloud.git] / version1 / src / java / iotcloud / KeyValue.java
1 package iotcloud;
2 import java.nio.ByteBuffer;
3
4 /**
5  * KeyValue entry for Slot.
6  * @author Brian Demsky <bdemsky@uci.edu>
7  * @version 1.0
8  */
9
10 class KeyValue extends Entry {
11         private IoTString key;
12         private IoTString value;
13
14         KeyValue(Slot slot, IoTString _key, IoTString _value) {
15                 super(slot);
16                 key=_key;
17                 value=_value;
18         }
19
20         IoTString getKey() {
21                 return key;
22         }
23
24         IoTString getValue() {
25                 return value;
26         }
27
28         static Entry decode(Slot slot, ByteBuffer bb) {
29                 int keylength=bb.getInt();
30                 int valuelength=bb.getInt();
31                 byte[] key=new byte[keylength];
32                 byte[] value=new byte[valuelength];
33                 bb.get(key);
34                 bb.get(value);
35                 return new KeyValue(slot, IoTString.shallow(key), IoTString.shallow(value));
36         }
37
38         void encode(ByteBuffer bb) {
39                 bb.put(Entry.TypeKeyValue);
40                 bb.putInt(key.length());
41                 bb.putInt(value.length());
42                 bb.put(key.internalBytes());
43                 bb.put(value.internalBytes());
44         }
45
46         int getSize() {
47                 return 2*Integer.BYTES+key.length()+value.length()+Byte.BYTES;
48         }
49
50         byte getType() {
51                 return Entry.TypeKeyValue;
52         }
53
54         public String toString() {
55                 return value.toString();
56         }
57
58         Entry getCopy(Slot s) {
59                 return new KeyValue(s, key, value);
60         }
61 }