remove println
[iotcloud.git] / src / js / iotjs / orig / slot.js
1 class Slot {
2     constructor(seqnum, machineid, prevhmac, hmac) {
3         this.SLOT_SIZE = 2048;
4         this.RESERVED_SPACE = 64;
5         this.HMAC_SIZE = 32;
6         (typeof seqnum === "number") ? this.seqnum = seqnum: throw new Error("seqnum should be a number");
7         (typeof machineid === "number") ? this.machineid = seqnum: throw new Error("machine should be a number");
8         this.livecount = 1;
9         this.seqnumlive = true;
10         (prevhmac && prevhmac instanceof Uint8Array) ? this.prevhmac = prevhmac: this.prevhmac = new Uint8Array(this.HMAC_SIZE));
11             (hmac && hmac instanceof Uint8Array) ? this.hmac = hmac: this.hmac = null;
12         this.entries = [];
13         this.freespace = this.SLOT_SIZE - getBaseSize(); //???????
14         }
15         getHMAC() {
16         return this.hmac;
17         }
18         getPrevHmac() {
19         return this.prevhmac;
20         }
21         addEntry(entry) {
22             if (entry && entry instanceof Entry) {
23                 var obj;
24                 this.entries.push(_.extend(obj, entry));
25                 this.livecount++;
26                 freespace -= entry.getSize();
27             }
28         }
29         addShallowEntry(entry){
30                 if(entry && entry instanceof Entry){
31                         this.entries.push(entry);
32                         this.livecount++;
33                 freespace -= entry.getSize();
34                 }
35         }
36         hasSpace(entry){
37                 var newfreespace = this.freespace - entry.getSize();
38                 return newfreespace > this.RESERVED_SPACE;
39         }
40         canFit(entry){
41                 var newfreespace = this.freespace - entry.getSize();
42                 return newfreespace >= 0; 
43         }
44         getEntries(){
45                 return this.entries;
46         }
47         static decode(array){
48                 var cond1 = (array && array instanceof Uint8Array);
49                 if(cond1){
50                 }
51         }
52 }