Lots of new things...

This commit is contained in:
Shoghi Cervantes Pueyo
2012-11-14 02:04:59 +01:00
parent 14e6fcb24e
commit 668994b5a4
9 changed files with 213 additions and 35 deletions

View File

@ -271,6 +271,27 @@ class Utils{
return pack("n", $value);
}
public static function readTriad($str){
list(,$unpacked) = unpack("N", "\x00".$str);
return (int) $unpacked;
}
public static function writeTriad($value){
return substr(pack("N", $value), 1);
}
public static function readDataArray($str, $len = 10){
$data = array();
$offset = 0;
for($i = 1; $i <= $len; ++$i){
$l = Utils::readTriad(substr($str, $offset, 3));
$offset += 3;
$data[] = substr($str, $offset, $l);
$offset += $l;
}
return $data;
}
public static function readInt($str){
list(,$unpacked) = unpack("N", $str);
return (int) $unpacked;