承接 8ctopus/byte-buffer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

8ctopus/byte-buffer

Composer 安装命令:

composer require 8ctopus/byte-buffer

包简介

A php buffer to work with binary data.

README 文档

README

packagist downloads min php version license tests code coverage badge lines of code

A php buffer to work with binary data.

install

composer require 8ctopus/byte-buffer

demo

use Oct8pus\ByteBuffer\ByteBuffer;
use Oct8pus\ByteBuffer\Endian;
use Oct8pus\ByteBuffer\Origin;

require_once __DIR__ . '/vendor/autoload.php';

echo "Let's create a new little endian buffer and write string Hello World\n";

$buffer = (new ByteBuffer())
    ->setEndian(Endian::LittleEndian)
    ->writeString('Hello World');

echo $buffer . "\n";
// hex (12/12): 48656c6c 6f20576f 726c6400 - Hello World.

echo "Add byte 0x07, word 0xFFFF and dword 0xAABBCCDD\n";

$buffer
    ->writeByte(0x07)
    ->writeWord(0xFFFF)
    ->writeDword(0xAABBCCDD);

echo $buffer;
// hex (19/19): 48656c6c 6f20576f 726c6400 07ffffdd ccbbaa - Hello World........

echo "\nSeek buffer back to origin\n";

$buffer->seek(0, Origin::Start);

echo $buffer;
// hex (0/19): 48656c6c 6f20576f 726c6400 07ffffdd ccbbaa - Hello World........

echo "\nRead string from buffer\n";

echo $buffer->readString() . "\n";
// Hello World

echo "\nRead byte, word and dword\n";

printf("0x%02X\n", $buffer->readByte());
printf("0x%04X\n", $buffer->readword());
printf("0x%08X\n", $buffer->readDword());
// 0x07
// 0xFFFF
// 0xAABBCCDD

echo "\nDelete World from buffer\n";

$buffer->delete(6, 5);

echo $buffer;
// hex (19/14): 48656c6c 6f200007 ffffddcc bbaa - Hello ........

echo "\nCalculate buffer crc32b\n";

echo '0x'. strtoupper($buffer->crc32b(true)) . "\n";
// 0xF3B2604E

echo "\nInsert Parrot at position 6\n";

$buffer
    ->seek(6, Origin::Start)
    ->insertChars('Parrot');

echo $buffer;
// hex (12/20): 48656c6c 6f205061 72726f74 0007ffff ddccbbaa - Hello Parrot........

echo "\nCopy Parrot to a new buffer\n";

$parrot = $buffer->copy(6, 6);

echo $parrot;
// hex (0/6): 50617272 6f74 - Parrot

echo "\nInvert Parrot\n";

echo $parrot->invert();
// hex (0/6): 746f7272 6150 - torraP

echo "\nCalculate hashes\n";
echo 'md5: ' . $parrot->md5(false) . "\n";
echo 'sha1: ' . $parrot->sha1(false) . "\n";
echo 'sha256: ' . $parrot->sha256(false) . "\n";
// md5: 4264ed2a05f9548fb3b26601c1c904c4
// sha1: d50da4682cdb41c803075168f5c132fd33ffa34d
// sha256: e2d6ddb19ca9c3396521297f4a09581c1187acb29931c8d4431941be71d2215c

echo "\nTruncate buffer\n";

echo $parrot->truncate();
// hex (0/0):

run tests

composer test

clean code

composer fix
composer fix-risky

reference

https://igor.io/2012/09/24/binary-parsing.html

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固