mirror of https://github.com/BOINC/boinc.git
Added version trackers and the BString class for BEncoded strings.
svn path=/trunk/boinc/; revision=12709
This commit is contained in:
parent
4e750be63b
commit
a07054742d
|
@ -4,6 +4,9 @@
|
|||
* Bittorrent features.
|
||||
* An integer starts with "i", has the value and then ends with "e".
|
||||
*/
|
||||
|
||||
$cvs_version_tracker[]="\$Id: belement.inc 12611 2007-05-08 08:25:13Z jbk $"; //Generated automatically - do not edit
|
||||
|
||||
class BInteger {
|
||||
private function __construct(){
|
||||
}
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
* It implements a BEncoded list - which always starts with l and ends with e.
|
||||
* In PHP lists are simply non-keyed (ie. standard keyed) arrays.
|
||||
*/
|
||||
|
||||
$cvs_version_tracker[]="\$Id: belement.inc 12611 2007-05-08 08:25:13Z jbk $"; //Generated automatically - do not edit
|
||||
|
||||
class BList {
|
||||
private function __construct(){
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* The BString class represents BEncoded strings for the serverside Bittorrent system.
|
||||
* A BEncoded string always starts with the length, then a ":" and then the actual data.
|
||||
* Strings are native in PHP.
|
||||
*/
|
||||
|
||||
$cvs_version_tracker[]="\$Id: belement.inc 12611 2007-05-08 08:25:13Z jbk $"; //Generated automatically - do not edit
|
||||
|
||||
class BString {
|
||||
private function __construct(){
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ordinary string decoded from $str
|
||||
* @throws an IllegalArgumentException in the case
|
||||
* that the string is malformed (ie. has more/less chars than specified
|
||||
* or does not correctly define a BEncoded string)
|
||||
*/
|
||||
public static function toString($str){
|
||||
list($length, $data) = explode(":", $str);
|
||||
if (!is_numeric($length)) throw new IllegalArgumentException("BEncoded string has non-numeric length specification.");
|
||||
if ($length != strlen($data)) throw new IllegalArgumentException("BEncoded string length does not match actual length of string.");
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a BEncoded string
|
||||
*/
|
||||
public static function toEncoded($str){
|
||||
return strlen($str).":".$str;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
Loading…
Reference in New Issue