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; }
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()); }