Recovering ByteArray's functionality

This commit is contained in:
斟酌 鵬兄 2014-01-24 14:40:36 +08:00
parent 0f55bec06b
commit 73b7f646b4

View File

@ -1,5 +1,20 @@
<?php
require_once 'errors.php';
class ERROR {
const INVALID_DATA = 1;
const UNDEFINED_DATA = 2;
const TYPE_MISSMATCH = 3;
const READ_ONLY = 11;
const GREATER_COMPARATIVE = 21;
const EOF = 100;
function __construct($type, $a, $b)
{
throw new Exception($type);
}
}
class ByteArray extends ArrayObject {
private $position = 0;
public function ByteArray($str = NULL) {
@ -423,14 +438,17 @@ class ByteArray extends ArrayObject {
return (($num = ($num < 0) ? $num + 256:$num) < 16) ? '0'.dechex($num):dechex($num);
}
}
/*tests
//* Tests
$a = new ByteArray();
$a->writeInt(12345);
$a->writeShort(11223);
$a->writeUnsignedInt(1125434357);
$a->position = 0;
echo "ReadInt: ";
echo $a->readInt()."\n";
echo "ReadShort: ";
echo $a->readShort()."\n";
echo "readUnsignedShort: ";
echo $a->readUnsignedInt()."\n";
$a->position = 0;
$a->writeDouble(1);
@ -448,19 +466,31 @@ class ByteArray extends ArrayObject {
$a->writeFloat(150);
$a->writeFloat(132.1);
$a->position = 0;
echo "readDouble: ";
echo $a->readDouble()."\n";
echo "readDouble: ";
echo $a->readDouble()."\n";
echo "readDouble: ";
echo $a->readDouble()."\n";
echo "readDouble: ";
echo $a->readDouble()."\n";
echo "readDouble: ";
echo $a->readDouble()."\n";
echo "readDouble: ";
echo $a->readDouble()."\n";
echo "readFloat: ";
echo $a->readFloat()."\n";
echo "readFloat: ";
echo $a->readFloat()."\n";
echo "readFloat: ";
echo $a->readFloat()."\n";
echo "readFloat: ";
echo $a->readFloat()."\n";
echo "readFloat: ";
echo $a->readFloat()."\n";
echo "readFloat: ";
echo $a->readFloat()."\n";
//*/
?>
?>