sysbot/bin
Composer 安装命令:
composer require sysbot/bin
包简介
Basic binary serialization/de-serialization utilities, providing support for both 32-bit and 64-bit PHP versions.
README 文档
README
Sysbot/bin is a library used by Sysbot. It handles serialization and deserialization of binary data, providing support for both 32-bit and 64-bit systems.
Changelog
You can find the changelog here.
Installation
Install the library with composer:
$ composer require sysbot/bin --prefer-stable
(32-bit systems) You must also install the required dependency brick/math.
$ composer require "brick/math:^0.10"
Usage
Here's an example on how to use the library.
<?php require_once 'vendor/autoload.php'; use Sysbot\Bin\Serializer; use Sysbot\Bin\Deserializer; // Serialization $serializer = new Serializer(); $serializer->addLong(15); // adds a 32-bit integer (little-endian) $long = PHP_INT_MAX; if (PHP_INT_SIZE === 4) { // 32-bit systems // since 32-bit systems can't handle 64-bit numbers, we must relay on the BigInteger class $long = BigInteger::of('9223372036854775807'); } $serializer->addLongLong($long, true); // adds a 64-bit integer (big-endian) $serializer->addString('Hi mom!'); // adds a string // casting a Serializer instance to a string will return the bytes echo bin2hex((string)$serializer); // outputs "0f0000007fffffffffffffff074869206d6f6d21" // Deserialization $deserializer = new Deserializer((string)$serializer); echo $deserializer->readLong(); // reads a 32-bit integer (little-endian), outputs "15" $long = $deserializer->readLongLong(true); // reads a 64-bit integer (big-endian) if (PHP_INT_SIZE === 4) { $long = (string)$long; // on 32-bit systems, an instance of the BigInteger class will be returned: to get the number, we must cast to string } echo $long; // outputs "9223372036854775807" echo $deserializer->readString(); // reads a string, outputs "Hi mom!"
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2022-04-18