Adding missing instructions to load missing Apache2 modules for Fidelius to work!
[iotcloud.git] / version1 / src / js / iotjs / src / keyvalue.js
1 'use strict';
2
3 var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4
5 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
7 function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
8
9 function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
10
11 var KeyValue = function (_Entry) {
12         _inherits(KeyValue, _Entry);
13
14         function KeyValue(slot, _key, _value) {
15                 _classCallCheck(this, KeyValue);
16
17                 if (!(slot instanceof Slot && _key instanceof IoTString && _value instanceof IoTString)) {
18                         throw new Error('Argument error ');
19                 }
20
21                 var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(KeyValue).call(this, slot));
22
23                 _this.key = _key;
24                 _this.value = _value;
25                 return _this;
26         }
27
28         _createClass(KeyValue, [{
29                 key: 'getKey',
30                 value: function getKey() {
31                         return this.key;
32                 }
33         }, {
34                 key: 'getValue',
35                 value: function getValue() {
36                         return this.value;
37                 }
38         }, {
39                 key: 'decode',
40                 value: function decode(slot, bb) {
41                         if (!(slot instanceof Slot && bb instanceof ByteBuffer)) {
42                                 throw new Error('Argument error');
43                         }
44                         var keylength = bb.getByte();
45                         var valuelength = bb.getByte();
46                         var key = new Uint8Array(keylength);
47                         var value = new Uint8Array(valuelength);
48                         var keystring = '';
49                         for (var i = 0; i < keylength; i++) {
50                                 keystring += bb.readByte();
51                         }
52                         var valuestring = '';
53                         for (var j = 0; j < keylength; j++) {
54                                 valuestring += bb.readByte();
55                         }
56                         for (var k = 0; k < keystring.length; k++) {
57                                 key[k] = keystring.charCodeAt(k);
58                         }
59                         for (var l = 0; l < valuestring.length; l++) {
60                                 value[l] = valuestring.charCodeAt(l);
61                         }
62                         return new KeyValue(slot, IoTString.shallow(key), IoTString.shallow(value));
63                 }
64         }, {
65                 key: 'encode',
66                 value: function encode(bb) {
67                         if (!(bb instanceof ByteBuffer)) {
68                                 throw new Error('argument error');
69                         }
70                         bb.writeByte(Entry.TypeKeyValue);
71                         bb.writeByte(this.key.length());
72                         bb.writeByte(this.value.length());
73                         bb.concat(this.key.internalBytes());
74                         bb.concat(this.value.internalBytes());
75                 }
76         }, {
77                 key: 'getSize',
78                 value: function getSize() {
79                         return 2 * 4 + this.jey.length() + this.value.length() + 1;
80                 }
81         }, {
82                 key: 'getType',
83                 value: function getType() {
84                         return Entry.TypeKeyValue;
85                 }
86         }, {
87                 key: 'toString',
88                 value: function toString() {
89                         return this.value.toString();
90                 }
91         }, {
92                 key: 'getCopy',
93                 value: function getCopy(s) {
94                         return new KeyValue(s, this.key, this.value);
95                 }
96         }]);
97
98         return KeyValue;
99 }(Entry);