예제 #1
0
 public function encode($data)
 {
     $result = new BitArray();
     while (strlen($data) >= 32) {
         $chunkLength = min(strlen($data), 2048 + 32 - 1);
         $result->append(self::CODE_UPPER_BS, 5);
         $result->append(0, 5);
         $result->append($chunkLength - 32, 11);
         $result->appendBytes(substr($data, 0, $chunkLength));
         $data = substr($data, $chunkLength);
     }
     if (strlen($data) > 0) {
         $result->append(self::CODE_UPPER_BS, 5);
         $result->append(strlen($data), 5);
         $result->appendBytes($data);
     }
     return $result;
 }
예제 #2
0
 public function testAppendBytes()
 {
     $array = new BitArray(2);
     $array->appendBytes('AB');
     $this->assertEquals(array(0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0), $array->asArray());
 }