Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
et-nik committed Mar 8, 2021
2 parents c493bc1 + 5382357 commit 401b4d2
Show file tree
Hide file tree
Showing 49 changed files with 1,893 additions and 2,495 deletions.
30 changes: 12 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
language: php

php:
- nightly
- 8.0
- 7.3
- 7.2
- 7.1
- 7.0
- 5.6
- 5.5
- 5.4
- hhvm


env:
matrix:
- PREFER_LOWEST="--prefer-lowest"
- PREFER_LOWEST=""

matrix:
allow_failures:
- php: 5.5
- php: 5.4
- php: hhvm

- php: nightly

before_install:
- composer self-update

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.xml

install:
- |
if [[ "$(phpenv version-name)" < "5.6" ]]
then
travis_retry composer require --no-interaction --prefer-source 'phpunit/phpunit:^4.8'
fi
- travis_retry composer update --no-interaction --prefer-source
- travis_retry composer update --no-interaction --prefer-source $PREFER_LOWEST
56 changes: 23 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Binn
====

[![Build Status](https://travis-ci.org/et-nik/binn-php.svg?branch=master)](https://travis-ci.org/et-nik/binn-php)
[![Build Status](https://travis-ci.com/et-nik/binn-php.svg?branch=master)](https://travis-ci.comd/et-nik/binn-php)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/et-nik/binn-php/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/et-nik/binn-php/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/et-nik/binn-php/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/et-nik/binn-php/?branch=master)

PHP Class for serialize to binary string.

Original Binn Library for C++ - https://github.com/liteserver/binn
Original C Binn Library: https://github.com/liteserver/binn

Binn Specification: https://github.com/liteserver/binn/blob/master/spec.md

Expand All @@ -26,7 +26,7 @@ Sequential arrays:
```php
use Knik\Binn\Binn;

$binn = new Binn;
$binn = new Binn();

// List
$array = [123, -456, 789];
Expand All @@ -36,7 +36,7 @@ $unserialized = $binn->unserialize($binnString); // Equal with $array

Numeric keys array:
```php
$binn = new Binn;
$binn = new Binn();

// Map
$array = [1 => "add", 2 => [-12345, 6789]];
Expand All @@ -46,7 +46,7 @@ $unserialized = $binn->unserialize($binnString); // Equal with $array

String keys array:
```php
$binn = new Binn;
$binn = new Binn();

// Object
$array = ["hello" => "world"];
Expand All @@ -57,51 +57,41 @@ $unserialized = $binn->unserialize($binnString); // Equal with $array
Mixed arrays:

```php
$binn = new Binn;
$binn = new Binn();
$array = [ ["id" => 1, "name" => "John"], ["id" => 2, "name" => "Eric"] ]

// A list of objects
$binnString = $binn->serialize($array);
$unserialized = $binn->unserialize($binnString); // Equal with $array
```

### Binn List

Serialize/unserialize sequential arrays

### Simple example

Blob:
```php
use Knik\Binn\BinnList;
$binn = new Binn();
$file = fopen('/path/to/file.jpg', 'rb');

$array = [4, -8875, 'text'];
// Filedata in binn structure
$bin1 = $binn->serialize($file);

$binn = new BinnList();
// Filedata in binn list structure
$bin2 = $binn->serialize(['file' => $file]);
```

// \xE0\x0F\x03\x20\x04\x41\xDD\x55\xA0\x04text\x00
$serialized = $binn->serialize($array);
### Symfony Serializer

```
You can use BinnEncoder with Symfony Serializer

```php
$binnString = "\xE0\x0F\x03\x20\x04\x41\xDD\x55\xA0\x04text\x00";
use Knik\Binn\Encoder\BinnEncoder;
use Symfony\Component\Serializer\Serializer;

$binn = new BinnList();
$unserialized = $binn->unserialize($binnString);

/*
Array
(
[0] => 4
[1] => -8875
[2] => text
)
*/
print_r($unserialized);
$encoders = [new BinnEncoder()];
$serializer = new Serializer([], $encoders);

$serializer->serialize("\x40\xD0\x06", 'binn');
```

### Original C++ library style
### Original C library style
```php
$binn = new BinnList();
$binn->addUint8(4);
Expand All @@ -122,4 +112,4 @@ $binn = new BinnList();
// \xE0\x11\x03\x20\x02\x01\xE0\x0B\x03\x20\x7B\x41\xFE\x38\x40\x03\x15
$serialized = $binn->serialize($array);

```
```
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
}
],
"require": {
"php": ">=5.6.3"
"php": ">=7.2",
"symfony/serializer": "^5"
},
"require-dev": {
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "^5.7"
"phpunit/phpunit": "^8.0 || ^9.0"
},
"autoload": {
"psr-4": {
"Knik\\Binn\\": "src/"
"Knik\\Binn\\": "src/",
"Knik\\Binn\\Tests\\": "tests/"
}
}
}
Loading

0 comments on commit 401b4d2

Please sign in to comment.