more code
[iotcloud.git] / src / java / iotcloud / KeyValue.java
index 36a56dc..ac19759 100644 (file)
@@ -2,33 +2,43 @@ package iotcloud;
 import java.nio.ByteBuffer;
 
 class KeyValue extends Entry {
-       byte[] key;
-       byte[] value;
-       KeyValue(byte[] _key, byte[] _value) {
+       private IoTString key;
+       private IoTString value;
+       
+       KeyValue(Slot slot, IoTString _key, IoTString _value) {
+               super(slot);
                key=_key;
                value=_value;
        }
+
+       IoTString getKey() {
+               return key;
+       }
+
+       IoTString getValue() {
+               return value;
+       }
        
-       static Entry decode(ByteBuffer bb) {
+       static Entry decode(Slot slot, ByteBuffer bb) {
                int keylength=bb.getInt();
                int valuelength=bb.getInt();
                byte[] key=new byte[keylength];
                byte[] value=new byte[valuelength];
                bb.get(key);
                bb.get(value);
-               return new KeyValue(key, value);
+               return new KeyValue(slot, IoTString.shallow(key), IoTString.shallow(value));
        }
 
        void encode(ByteBuffer bb) {
                bb.put(Entry.TypeKeyValue);
-               bb.putInt(key.length);
-               bb.putInt(value.length);
-               bb.put(key);
-               bb.put(value);
+               bb.putInt(key.length());
+               bb.putInt(value.length());
+               bb.put(key.internalBytes());
+               bb.put(value.internalBytes());
        }
 
        int getSize() {
-               return 2*Integer.BYTES+key.length+value.length+Byte.BYTES;
+               return 2*Integer.BYTES+key.length()+value.length()+Byte.BYTES;
        }
 
        byte getType() {