thesis/endian 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

thesis/endian

Composer 安装命令:

composer require thesis/endian

包简介

Library for encoding and decoding numbers in either big-endian or little-endian order.

README 文档

README

PHP Version Requirement GitHub Release Code Coverage

Pack and unpack binary integers and floats in any byte order.

Installation

composer require thesis/endian

Usage

use Thesis\Endian;

// Big endian (= network byte order)
$bytes = Endian\Order::Big->packInt32(-200);
$value = Endian\Order::Big->unpackInt32($bytes); // -200
$bytes = Endian\Order::Network->packInt32(-200);
$value = Endian\Order::Network->unpackInt32($bytes); // -200

// Little endian
$bytes = Endian\Order::Little->packFloat(2.2);
$value = Endian\Order::Little->unpackFloat($bytes); // 2.2

// Native byte order of the current machine
$order = Endian\Order::native(); // Order::Big or Order::Little

Design decisions

No narrow int types on input

Pack methods accept plain int rather than narrow PHPStan types like Int8 or Int32. This is intentional: requiring callers to carry and assert narrow types would flood driver code with redundant checks and type imports. Thus, we've decided to keep the validation on our side.

Bounds are checked with assert(), which means zero overhead in production when assertions are disabled (zend.assertions = -1).

No object wrappers for 8/16/32-bit

8/16/32-bit integers are represented as native PHP int, not value objects. This avoids allocation and method-call overhead on every pack/unpack — important in tight loops typical of binary protocol parsing.

64-bit integers

64-bit values use BcMath\Number to handle the full unsigned range beyond PHP_INT_MAX:

use Thesis\Endian;
use BcMath\Number;

$bytes = Endian\Order::Big->packUint64(new Number('18446744073709551615'));
$value = Endian\Order::Big->unpackUint64($bytes); // 18446744073709551615

Supported types

Type PHP type Range
int8 int −128 .. 127
uint8 int 0 .. 255
int16 int −32 768 .. 32767
uint16 int 0 .. 65535
int32 int −2147483648 .. 2147483647
uint32 int 0 .. 4294967295
int64 BcMath\Number −2⁶³ .. 2⁶³−1
uint64 BcMath\Number 0 .. 2⁶⁴−1
float float 32-bit IEEE 754
double float 64-bit IEEE 754

thesis/endian 适用场景与选型建议

thesis/endian 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 48.33k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 01 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 thesis/endian 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 48.33k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 19
  • 依赖项目数: 7
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-16