1 class KeyValue extends Entry{
2 constructor(slot,_key,_value){
3 if(!(slot instanceof Slot && _key instanceof IoTString && _value instanceof IoTString)){
4 throw new Error('Argument error ');
17 if(!(slot instanceof Slot && bb instanceof ByteBuffer)){
18 throw new Error('Argument error');
20 var keylength = bb.getByte();
21 var valuelength = bb.getByte();
22 var key = new Uint8Array(keylength);
23 var value = new Uint8Array(valuelength);
25 for(var i =0 ;i<keylength ; i++){
26 keystring += bb.readByte();
29 for(var j =0 ;j<keylength ; j++){
30 valuestring += bb.readByte();
32 for(var k = 0; k< keystring.length; k++){
33 key[k] = keystring.charCodeAt(k);
35 for(var l = 0; l< valuestring.length; l++){
36 value[l] = valuestring.charCodeAt(l);
38 return new KeyValue(slot,IoTString.shallow(key),IoTString.shallow(value));
42 if(!(bb instanceof ByteBuffer)){
43 throw new Error('argument error');
45 bb.writeByte(Entry.TypeKeyValue);
46 bb.writeByte(this.key.length());
47 bb.writeByte(this.value.length());
48 bb.concat(this.key.internalBytes());
49 bb.concat(this.value.internalBytes());
52 return 2*4+this.jey.length()+this.value.length()+1;
56 return Entry.TypeKeyValue;
60 return this.value.toString();
63 return new KeyValue(s,this.key,this.value);