/ByteBuffer

This is a improved rewrite of the Project from OleMchls You can also call this a pack() wrapper.

Primary LanguagePHP

PHP Library for reading and writing binary data

Build Status

This is a improved rewrite of the Project from OleMchls You can also call this a pack() wrapper.

Additional Features

  • Autoincrement Offset
  • Write Int32, Int64, UInt64 and UTF8 Strings

Install

Installation should be done via composer.

composer require msst/byte-buffer

Or

{
    "require": {
        "msst/byte-buffer": "dev-master"
    }
}

Example

A simple usage example could look like this

<?php

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

use MSST\ByteBuffer\Buffer;

$text1 = 'channel_one';
$text2 = "This is a utf8 test message. 😄";

$buffer = new Buffer(4 + 1 + 4 + strlen($text1) + strlen($text2));
$buffer->writeInt32($buffer->length());
$buffer->writeInt8(0x1);
$buffer->writeInt32(strlen($text1));
$buffer->write($text1);
$buffer->writeUtf8($text2);

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$result = socket_connect($socket, '127.0.0.1', 3542);

socket_write($socket, (string) $buffer, $buffer->length());

Testing

Just working under php > 7.1

./vendor/bin/phpunit

License

Licensed under the MIT license.

Original Project: ByteBuffer by OleMchls