muvon/kiss-binary-codec
Composer 安装命令:
composer require muvon/kiss-binary-codec
包简介
Binary codec for encoding multiple structures with predefined config
README 文档
README
Binary codec for encoding multiple structures with predefined config
It works only with array as input cuz created for complex structure and detect best encoding option for data and return mostly optimized data for hashes and ints with big arrays
Encoder flow
Encoder uses pack to encode and unpack to decode with special modifications and extra addons.
Binary contains of data
- 1 byte protocol version
- 4 bytes size of meta
- x bytes meta data with pack info and keys encoded with gzip
- x bytes encoded binary data
Sample of usage
$data = json_decode('[null,[{"hash":"80ca095ed10b02e53d769eb6eaf92cd04e9e0759e5be4a8477b42911ba49c78f","strippedsize":215,"size":215,"weight":860,"height":1,"version":1,"versionHex":"00000001","merkleroot":"fa3906a4219078364372d0e2715f93e822edd0b47ce146c71ba7ba57179b50f6","tx":["fa3906a4219078364372d0e2715f93e822edd0b47ce146c71ba7ba57179b50f6"],"time":1318055359,"mediantime":1318055359,"nonce":272255,"bits":"1e0ffff0","difficulty":"0.000244140625","chainwork":"0000000000000000000000000000000000000000000000000000000000200020","nTx":1,"previousblockhash":"12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2","nextblockhash":"13957807cdd1d02f993909fa59510e318763f99a506c4c426e3b254af09f40d7"},{"hash":"a4ad8c78654e76a729c12dd10522a40ba7077167bbf5b28fc9c71d25fcd67226","strippedsize":215,"size":215,"weight":860,"height":20,"version":1,"versionHex":"00000001","merkleroot":"732300fac0d661a2bf01ef2f521460cc26eeb608939c196ab34221f6533d60f7","tx":["732300fac0d661a2bf01ef2f521460cc26eeb608939c196ab34221f6533d60f7"],"time":1318474885,"mediantime":1318474854,"nonce":1164,"bits":"1e0ffff0","difficulty":"0.000244140625","chainwork":"0000000000000000000000000000000000000000000000000000000001500150","nTx":1,"previousblockhash":"6ea63d7aa791c13042b72c6855f089ef78ed45c3b8dc3263fc0e8cb8b3070f05","nextblockhash":"31ed087d6effc647d37b6e04f7e7da9e04b270d95262b21c8275aa10fc0c7104"},{"hash":"537ad94bc3b5927e32cdb6bc2d59adf54a010901e45f1602738a709d4d67f53b","strippedsize":215,"size":215,"weight":860,"height":3422,"version":1,"versionHex":"00000001","merkleroot":"003632bba01886ab81df69d734665ec00562f6363e82286c4ace45d700d86f8e","tx":["003632bba01886ab81df69d734665ec00562f6363e82286c4ace45d700d86f8e"],"time":1318483933,"mediantime":1318483922,"nonce":1246,"bits":"1e0fffff","difficulty":"0.0002441371325370145","chainwork":"00000000000000000000000000000000000000000000000000000000d5f0837f","nTx":1,"previousblockhash":"4e2695a5d2d0c05ba6c264a51cea731cd61567b66e54cb0450f05b169fc27ea5","nextblockhash":"2707f4d6ca57db167afb88b98e97f8956d4c34cc9c6cc5155ad1e48330278241"}]]', true); var_dump(binary_pack($data)); // string(953) var_dump(msgpack_pack($data)); // string(1844)
Unique features
The coded uses automatic detection data and encode is with best way.
- Hex strings (transaction hash for example)
- Big numeric as string converted to binary without losing precision
- Big float as string converted to binary without losing precision
- Hash map extracts all keys and converted as plain
- Int size determined by input value and it uses smaller one
Test coverage
- String encode
- Bool encode
- Integer encode
- Float encode
- Hex encode
- Int list encode
- Hex list encode
- Null encode
- Int as string encode
- Float as string encode
- Ipv 4 encode
- List encode
- Map encode
muvon/kiss-binary-codec 适用场景与选型建议
muvon/kiss-binary-codec 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.36k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 03 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「encoder」 「lightweight」 「decoder」 「kiss」 「binary」 「codec」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 muvon/kiss-binary-codec 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 muvon/kiss-binary-codec 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 muvon/kiss-binary-codec 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Streaming parser to extract tarballs with ReactPHP.
base62 encoder and decoder also for big numbers with Laravel integration
PHP Library for Encoding.com's XML API
A Base91 implementation as a composer package
Serialization library
A TOML parser and encoder for PHP with AST access and collected parse errors
统计信息
- 总下载量: 1.36k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-03-31