Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dahlia/bencodex-php
Bencodex reader/writer for PHP
https://github.com/dahlia/bencodex-php
bencodex bencoding php serialization
Last synced: 20 days ago
JSON representation
Bencodex reader/writer for PHP
- Host: GitHub
- URL: https://github.com/dahlia/bencodex-php
- Owner: dahlia
- License: mit
- Created: 2021-10-16T16:41:30.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-15T16:40:20.000Z (about 2 years ago)
- Last Synced: 2024-10-03T16:36:08.432Z (about 1 month ago)
- Topics: bencodex, bencoding, php, serialization
- Language: PHP
- Homepage: https://packagist.org/packages/bencodex/bencodex
- Size: 326 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Bencodex reader/writer for PHP
==============================[![Packagist Version][]][Packagist]
[![MIT License][]](LICENSE)
[![GitHub Actions Status][]][GitHub Actions][Packagist]: https://packagist.org/packages/bencodex/bencodex
[Packagist Version]: http://poser.pugx.org/bencodex/bencodex/v
[MIT License]: http://poser.pugx.org/bencodex/bencodex/license
[GitHub Actions Status]: https://github.com/dahlia/bencodex-php/actions/workflows/build.yaml/badge.svg
[GitHub Actions]: https://github.com/dahlia/bencodex-php/actions/workflows/build.yamlThis package implements [Bencodex] serialization format which extends
[Bencoding]. Complianet with Bencodex 1.2.~~~ php
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 Version Requirement][]][Packagist]
- PHP 5.4 or later
- [iconv] extension (`--with-iconv`)[PHP Version Requirement]: http://poser.pugx.org/bencodex/bencodex/require/php
[iconv]: https://www.php.net/manual/en/book.iconv.phpType correspondences
--------------------| PHP | Bencodex |
|----------------------------------------|---------------------------|
| Null | Null |
| Boolean | Boolean |
| Integer | Integer |
| Double[^1] | Integer (truncated) |
| Numeric string[^2] | Integer ≥ [`PHP_INT_MAX`] |
| String which can be decoded as Unicode | Text[^2] |
| String otherwise | Binary[^2] |
| List-like array[^3] | List |
| Map-like array[^1] | Dictionary |
| Object | Dictionary |[^1]: One-way types only available for encoding.
[^2]: One-way types only available for decoding.
[^3]: Determined by [`array_is_list()` function][array_is_list].[array_is_list]: https://www.php.net/manual/en/function.array-is-list
[`PHP_INT_MAX`]: https://www.php.net/manual/en/reserved.constants.php#constant.php-int-maxUsage
------ [`\Bencodex\encode(mixed $value): string`][encode]: Encodes a PHP `$value`
into Bencodex data.
- [`\Bencodex\decode(string $bencodex): mixed`][decode]: Decodes Bencodex data
into a PHP value.The above APIs are merely façade, and optional parameters are omitted.
See the [complete API docs][1] as well.[encode]: https://dahlia.github.io/bencodex-php/namespaces/bencodex.html#function_encode
[decode]: https://dahlia.github.io/bencodex-php/namespaces/bencodex.html#function_decode
[1]: https://dahlia.github.io/bencodex-php/[Bencodex]: https://bencodex.org/
[Bencoding]: https://www.bittorrent.org/beps/bep_0003.html#bencoding