imedge/protocol-netstring 问题修复 & 功能扩展

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

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

imedge/protocol-netstring

最新稳定版本:v0.4.0

Composer 安装命令:

composer require imedge/protocol-netstring

包简介

Asynchronous NetString implementation for AMPHP

README 文档

README

This library implements the NetString protocol and provides a NetStringReader, a NetStringWriter and a bidirectional NetStringConnection implementation for AMPHP.

Coding Standards Unit Tests Static Analysis PHPStan Level 9 Minimum PHP Version: 8.1 License: MIT Version

Installation

This package can be installed as a Composer dependency on PHP 8.1 and later.

composer require imedge/protocol-netstring

Usage

NetStringReader

Sample Code

<?php

use Amp\ByteStream\ReadableBuffer;
use IMEdge\Protocol\NetString\NetStringReader;

$netString = new NetStringReader(new ReadableBuffer('5:Hello,6:world!,'));
foreach ($netString->packets() as $packet) {
    var_dump($packet);
}

Output

string(5) "Hello"
string(6) "world!"

NetStringWriter

Sample Code

<?php

use Amp\ByteStream\WritableBuffer;
use IMEdge\Protocol\NetString\NetStringWriter;

$netString = new NetStringWriter($out = new WritableBuffer());
$netString->write('Hello');
$netString->write(' ');
$netString->write('World!');
$netString->close();
var_dump($out->buffer());

Output

string(21) "5:Hello,1: ,6:World!,"

NetStringConnection

A NetStingConnection allows for bidirectional NetString communication.

Sample Code

<?php

use Amp\ByteStream\ReadableBuffer;
use Amp\ByteStream\WritableBuffer;
use IMEdge\Protocol\NetString\NetStringConnection;

$netString = new NetStringConnection(new ReadableBuffer('5:Hello,6:world!,'), $out = new WritableBuffer());
$netString->write('Hi!');
foreach ($netString->packets() as $packet) {
    var_dump($packet);
}
$out->close();
var_dump($out->buffer());

Output

string(5) "Hello"
string(6) "world!"
string(6) "3:Hi!"

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-28