Added Js code (40%)
[iotcloud.git] / src / js / iotjs / src / entry.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 var Entry = function () {
8     function Entry(slot) {
9         _classCallCheck(this, Entry);
10
11         if (slot && slot instanceof Slot) {
12
13             this.TypeKeyValue = 1;
14             this.TypeLastmessage = 2;
15             this.TypeRejectedMessage = 3;
16             this.TypeTableStatus = 4;
17             this.liveStatus = true;
18             this.parentslot = slot;
19         }
20     }
21
22     _createClass(Entry, [{
23         key: "isLive",
24         value: function isLive() {
25             return this.liveStatus;
26         }
27     }, {
28         key: "setDead",
29         value: function setDead() {
30             this.liveStatus = false;
31             parentslot.decrementLiveCount();
32         }
33
34         //must be overriden.
35
36     }, {
37         key: "encode",
38         value: function encode(bytebuffer) {}
39     }, {
40         key: "getSize",
41         value: function getSize() {}
42     }, {
43         key: "getType",
44         value: function getType() {}
45     }, {
46         key: "getCopy",
47         value: function getCopy(slot) {
48             if (slot && slot instanceof Slot) {}
49         }
50     }], [{
51         key: "decode",
52         value: function decode(slot, bytebuffer) {
53             if (slot instanceof Slot && bytebuffer instanceof ByteBuffer) {
54                 var type = bytebuffer.readByte();
55                 switch (type) {
56                     case this.TypeKeyValue:
57                         return KeyValue.decode(slot, bytebuffer);
58                     case this.TypeLastmessage:
59                         return LastMessage.decode(slot, bytebuffer);
60                     case this.TypeRejectedMessage:
61                         return RejectedMessage.decode(slot, bytebuffer);
62                     case this.TypeTableStatus:
63                         return TableStatus.decode(slot, bytebuffer);
64                     default:
65                         throw new Error("Unrecognized Entry Type: " + type);
66                 }
67             }
68         }
69     }]);
70
71     return Entry;
72 }();