bencodex / bencodex
Bencodex reader/writer for PHP
Installs: 1 078
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.4.0
- ext-iconv: *
- symfony/polyfill-php70: <=1.19.0
Requires (Dev)
- ext-json: *
- friendsofphp/php-cs-fixer: >=1.13.3
- phpunit/phpunit: >=4.8.36
README
This package implements Bencodex serialization format which extends Bencoding. Complianet with Bencodex 1.2.
php > echo Bencodex\encode(['foo' => 123, 'bar' => [true, false]]); du3:barltfeu3:fooi123ee php > var_dump(Bencodex\decode('du3:barltfeu3:fooi123ee')); object(stdClass)#4 (2) { ["bar"]=> array(2) { [0]=> bool(true) [1]=> bool(false) } ["foo"]=> int(123) }
Requirements
- PHP 5.4 or later
- iconv extension (
--with-iconv
)
Type correspondences
PHP | Bencodex |
---|---|
Null | Null |
Boolean | Boolean |
Integer | Integer |
Double1 | Integer (truncated) |
Numeric string2 | Integer ≥ PHP_INT_MAX |
String which can be decoded as Unicode | Text2 |
String otherwise | Binary2 |
List-like array3 | List |
Map-like array1 | Dictionary |
Object | Dictionary |
Usage
\Bencodex\encode(mixed $value): string
: Encodes a PHP$value
into Bencodex data.\Bencodex\decode(string $bencodex): mixed
: Decodes Bencodex data into a PHP value.
The above APIs are merely façade, and optional parameters are omitted. See the complete API docs as well.