[Service] Integrate DeviceHome and SignalingServer
[platform/framework/web/wrtjs.git] / device_home / node_modules / qrcode / lib / core / bit-buffer.js
1 function BitBuffer () {
2   this.buffer = []
3   this.length = 0
4 }
5
6 BitBuffer.prototype = {
7
8   get: function (index) {
9     var bufIndex = Math.floor(index / 8)
10     return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) === 1
11   },
12
13   put: function (num, length) {
14     for (var i = 0; i < length; i++) {
15       this.putBit(((num >>> (length - i - 1)) & 1) === 1)
16     }
17   },
18
19   getLengthInBits: function () {
20     return this.length
21   },
22
23   putBit: function (bit) {
24     var bufIndex = Math.floor(this.length / 8)
25     if (this.buffer.length <= bufIndex) {
26       this.buffer.push(0)
27     }
28
29     if (bit) {
30       this.buffer[bufIndex] |= (0x80 >>> (this.length % 8))
31     }
32
33     this.length++
34   }
35 }
36
37 module.exports = BitBuffer