1. Go to this page and download the library: Download alpari/binary-protocol library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alpari / binary-protocol example snippets
namespace Alpari\BinaryProtocol;
use Alpari\BinaryProtocol\Stream\StreamInterface;
/**
* Declares the type that can be packed/unpacked from/to binary stream
*/
interface TypeInterface
{
/**
* Reads a value from the stream
*
* @param StreamInterface $stream Instance of stream to read value from
* @param string $path Path to the item to simplify debug of complex hierarchical structures
*
* @return mixed
*/
public function read(StreamInterface $stream, string $path);
/**
* Writes the value to the given stream
*
* @param mixed $value Value to write
* @param StreamInterface $stream Instance of stream to write to
* @param string $path Path to the item to simplify debug of complex hierarchical structures
*
* @return void
*/
public function write($value, StreamInterface $stream, string $path): void;
/**
* Calculates the size in bytes of single item for given value
*
* @param mixed $value Value to write
* @param string $path Path to the item to simplify debug of complex hierarchical structures
*
* @return int
*/
public function sizeOf($value = null, string $path =''): int;
}
/**
* SchemeDefinitionInterface represents a class that holds definition of his scheme
*/
interface SchemeDefinitionInterface
{
/**
* Returns the definition of class scheme as an associative array if form of [property => type]
*/
public static function getDefinition(): array;
}
use Alpari\BinaryProtocol\Type\Int16BE as Int16;
use Alpari\BinaryProtocol\SchemeDefinitionInterface;
/**
* ApiVersions response data
*/
class ApiVersionsResponseMetadata implements SchemeDefinitionInterface
{
/**
* Numerical code of API
*
* @var integer
*/
public $apiKey;
/**
* Minimum supported version.
*
* @var integer
*/
public $minVersion;
/**
* Maximum supported version.
*
* @var integer
*/
public $maxVersion;
/**
* @inheritdoc
*/
public static function getDefinition(): array
{
return [
'apiKey' => [Int16::class],
'minVersion' => [Int16::class],
'maxVersion' => [Int16::class],
];
}
}