定制 pigeonboys/php-binary-parser 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pigeonboys/php-binary-parser

Composer 安装命令:

composer require pigeonboys/php-binary-parser

包简介

A PHP library for parsing binary data, with full support for signed/unsigned integers and endian-aware formats.

README 文档

README

A lightweight PHP library for parsing binary data from byte arrays. Supports signed and unsigned integers, arrays, and endian-aware formats (big/little endian). Ideal for reading hardware data streams, binary protocols, or any low-level byte-oriented data.

Features

  • Supports 8, 16, 24, 32, and 64-bit integers
  • Signed and unsigned parsing
  • Little-endian and big-endian support
  • Bytes are consumed from the buffer after each read
  • Multi-read support (readMany())
  • Resettable buffer with resetBuffer()
  • Type-safe with meaningful exceptions

Installation

You can install via Composer:

composer require pigeonboys/php-binary-parser

PHP version 8.0+ is required.

Usage

Basic Usage

use PigeonBoys\PhpBinaryParser\BinaryParser;

$buffer = [0x12, 0x34, 0x56, 0x78];
$parser = new BinaryParser($buffer);

// Read an unsigned 16-bit integer in big-endian
$value = $parser->int16()->unsigned()->bigEndian()->read();
echo $value; // 4660

// After this read, the first two bytes are removed from the buffer
echo $parser->bytesRemaining(); // 2

Reading Multiple Values

$parser = new BinaryParser([0x01, 0x02, 0x03, 0x04]);

// Read two unsigned 8-bit integers
$values = $parser->int8()->unsigned()->readMany(2);
print_r($values); // [1, 2]

// Only remaining bytes are left in the buffer
echo $parser->bytesRemaining(); // 2

Resetting Buffer

$parser->resetBuffer(); // restores all original bytes

Methods

  • int8(), int16(), int24(), int32(), int64()Set the bitness
  • signed(), unsigned()Set the signedness
  • littleEndian(), bigEndian()Set the endianness
  • read()Read a single value and consume bytes from the buffer
  • readMany(int $count)Read multiple values and consume bytes from the buffer
  • resetBuffer()Reset buffer to original content
  • bytesRemaining()Get the number of bytes left

Exceptions

  • BitnessAlreadySetExceptionThrown if you try to set the bitness more than once before reading.
  • EndiannessAlreadySetExceptionThrown if you try to set the endianness more than once before reading.
  • SignednessAlreadySetExceptionThrown if you try to set signedness more than once before reading.
  • BitnessNotSetExceptionThrown if you attempt to read an integer without first specifying the bitness.
  • EndiannessNotSetExceptionThrown if you attempt to read a multi-byte integer without specifying endianness (except 8-bit).
  • SignednessNotSetExceptionThrown if you attempt to read an integer without specifying signed or unsigned.
  • InvalidLengthExceptionThrown if the number of bytes requested for readBytes() is less than 1.
  • InvalidCountExceptionThrown if readMany() is called with a count less than 1.
  • CurrentBufferUnderflowExceptionThrown if there are not enough bytes left in the buffer to satisfy a read.

pigeonboys/php-binary-parser 适用场景与选型建议

pigeonboys/php-binary-parser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 pigeonboys/php-binary-parser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pigeonboys/php-binary-parser 我们能提供哪些服务?
定制开发 / 二次开发

基于 pigeonboys/php-binary-parser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-02