| 26 | */ |
| 27 | |
| 28 | class QRbitstream { |
| 29 | |
| 30 | public $data = array(); |
| 31 | |
| 32 | //---------------------------------------------------------------------- |
| 33 | public function size() |
| 34 | { |
| 35 | return count($this->data); |
| 36 | } |
| 37 | |
| 38 | //---------------------------------------------------------------------- |
| 39 | public function allocate($setLength) |
| 40 | { |
| 41 | $this->data = array_fill(0, $setLength, 0); |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | //---------------------------------------------------------------------- |
| 46 | public static function newFromNum($bits, $num) |
| 47 | { |
| 48 | $bstream = new QRbitstream(); |
| 49 | $bstream->allocate($bits); |
| 50 | |
| 51 | $mask = 1 << ($bits - 1); |
| 52 | for($i=0; $i<$bits; $i++) { |
| 53 | if($num & $mask) { |
| 54 | $bstream->data[$i] = 1; |
| 55 | } else { |
| 56 | $bstream->data[$i] = 0; |
| 57 | } |
| 58 | $mask = $mask >> 1; |
| 59 | } |
| 60 | |
| 61 | return $bstream; |
| 62 | } |
| 63 | |
| 64 | //---------------------------------------------------------------------- |
| 65 | public static function newFromBytes($size, $data) |
| 66 | { |
| 67 | $bstream = new QRbitstream(); |
| 68 | $bstream->allocate($size * 8); |
| 69 | $p=0; |
| 70 | |
| 71 | for($i=0; $i<$size; $i++) { |
| 72 | $mask = 0x80; |
| 73 | for($j=0; $j<8; $j++) { |
| 74 | if($data[$i] & $mask) { |
| 75 | $bstream->data[$p] = 1; |
| 76 | } else { |
| 77 | $bstream->data[$p] = 0; |
| 78 | } |
| 79 | $p++; |
| 80 | $mask = $mask >> 1; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | return $bstream; |
| 85 | } |
nothing calls this directly
no outgoing calls
no test coverage detected