定制 calamity-inc/u64-dyn 二次开发

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

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

calamity-inc/u64-dyn

Composer 安装命令:

composer require calamity-inc/u64-dyn

包简介

Variable-length 64-bit integer codings that take at most 9 bytes.

README 文档

README

Variable-length 64-bit integer codings that take at most 9 bytes.

Guide

  • Biased variants (indicated with a b) need less bytes to encode certain sequences.
  • Prefixed variants (indicated with a p) are a lot faster to read due to the first byte indicating the sequence length.
  • For signed codings, there is also a to indicate arithmetic negation as opposed to bitwise negation.

Implementations

Specifications

u64_dyn

The first 56 bits of the integer are encoded in up to eight little-endian 7-bit groups where the most significant bit indicates if another byte follows. The final 8 bits are encoded as-is.

Value Encoded As
0x7f 7f
0x80 80 01
0x4000 80 80 01
0xffffffffffffffff ff ff ff ff ff ff ff ff ff

u64_dyn_b

Same as u64_dyn but for each continuation bit (i.e., "another byte follows"), 1 is subtracted from the remaining value after shifting. Decoding compensates by adding a bias.

Value Encoded As
0x7f 7f
0x80 80 00
0x4000 80 7f
0xffffffffffffffff ff fe fe fe fe fe fe fe fe

Contrived sequences which would exceed 2^64 (e.g. ff ff fe fe fe fe fe fe fe) are illegal. Decoders can detect them (by checking v > UINT64_MAX - bias before adding the bias) and should return an error appropriately.

u64_dyn_p

Same as u64_dyn but the continuation bits are all moved to the first byte:

0xxxxxxx
10xxxxxx xxxxxxxx
110xxxxx xxxxxxxx xxxxxxxx
1110xxxx xxxxxxxx xxxxxxxx xxxxxxxx
11110xxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx
111110xx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx
1111110x xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx
11111110 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx
11111111 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx

Prefixing does not change the length of coded values.

Value Encoded As
0x7f 7f
0x80 80 02
0x4000 C0 80 02
0xffffffffffffffff ff ff ff ff ff ff ff ff ff

u64_dyn_bp

This coding uses the biasing of u64_dyn_b and the prefixing of u64_dyn_p.

Value Encoded As
0x7f 7f
0x80 80 00
0x4000 80 fe
0xffffffffffffffff ff 7f bf df ef f7 fb fd fe

i64_dyn_a

The i64 value is split into (neg, u63) like so:

neg := i64 < 0
if neg:
    u63 := (~i64 + 1) & ~(1 << 63)
else:
    u63 := i64

This is rejoined into a u64 with neg in bit 6:

u64 := (neg << 6) | ((u63 & ~0x3f) << 1) | (u63 & 0x3f)

This value is then encoded using u64_dyn. When decoding, if neg is set the original value is recovered with:

i64 := ~(u63 - 1) | (1 << 63)
Value Encoded As
42 2a
0x2000 80 80 01
-1 41
-9223372036854775808 40

i64_dyn_b

The i64 value is split into (neg, u63) like so:

neg := i64 < 0
if neg:
    u63 := ~i64
else:
    u63 := i64

This is rejoined into a u64 with neg in bit 6:

u64 := (neg << 6) | ((u63 & ~0x3f) << 1) | (u63 & 0x3f)

This value is then encoded using u64_dyn_b. Decoding is the same in reverse.

Value Encoded As
42 2a
0x2000 80 7f
-1 40
-9223372036854775808 ff fe fe fe fe fe fe fe fe

i64_dyn_bp

The i64 value is converted to u64 just like in i64_dyn_b. However, in this case the u64 is coded with u64_dyn_bp.

Value Encoded As
42 2a
0x2000 80 fe
-1 40
-9223372036854775808 ff 7f bf df ef f7 fb fd fe

calamity-inc/u64-dyn 适用场景与选型建议

calamity-inc/u64-dyn 是一款 基于 C 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 08 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 calamity-inc/u64-dyn 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: C

其他信息

  • 授权协议: Unlicense
  • 更新时间: 2025-08-11