Download the PHP package alpari/binary-protocol without Composer

On this page you can find all versions of the php package alpari/binary-protocol. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package binary-protocol

Alpari BinaryProtocol library

alpari/binary-protocol is a PHP library that provides an API for working with binary protocols, like FCGI, ApacheKafka and others. Applications can use this library to describe binary data and work with high-level API without manual working with binary data packing/unpacking.

Installation

alpari/binary-protocol can be installed with composer. To download this library please type:

TypeInterface API

The TypeInterface API describes low-level representation of data, for example Int8, Int16, String, etc...

Each data type should be added as a separate class implementing TypeInterface contract with logic of packing and unpacking data to/from StreamInterface

As you can see there are two main methods which are read() and write() that are used for reading and writing binary data to the stream.

The method sizeOf() is used for calculation of data size in bytes. For simple data types it will return constant value and for more complex structures like arrays or objects it should be able to calculate the size of such field.

Method getFormat() is declared in the interface, but it is not used right now. It can be used later for fixed-size arrays or structures to speed up parsing, for example, array of Int16.

SchemeDefinitionInterface API

SchemeDefinitionInterface helps to use complex binary data structures in your application. Each complex type from the binary protocol should be represented as a separate DTO (Plain PHP object with properties) implementing the SchemeDefinitionInterface and it's method getDefinition().

Here is an example of definition of binary packet that is used for Kafka client:

To add the definition to your existing class, just add "property" => "type" mapping as a scheme definition. Please note that each property type is declared as an array in the getDefinition() method. This format is used to define additional arguments for complex types.

ArrayOf type

ArrayOf type is used to declare the sequence of repeated binary items (integers, strings or objects). It has several options that can be applied as an associative array of values.

Available options for ArrayOf are:

BinaryString type

BinaryString class is general representation of any string or raw buffers with binary data. Typically it is encoded as buffer length field and sequence of bytes as a data.

Available options for BinaryString are:

envelope feature is used for some protocols when low-level protocol just defines some buffer and top-level protocol extracts specific packet from this temporary buffer. Example is TCP packet over IP.

By default BinaryString uses Int16 in big-endian encoding for size, if you need more data, just configure the size option accordingly.

SchemeType type

SchemeType class represents a complex structure that can be mapped to PHP's object instance. It has following options:

Note: if your SomeClass class implements the SchemeDefinitionInterface, then you can simply refer to it in the scheme as [SomeClass::class].

BinaryProtocol class usage

This library introduces BinaryProtocol class as a top-level binary coder/decoder API. To read the data, please, prepare a suitable data stream via implementation of StreamInterface contract or just utilize StringStream built-in class to write content into temporary buffer. Then just ask protocol to read or write something in it:

Lazy-evaluated fields

In some cases binary protocols contains fields that depend on existing data, for example: packet length, CRC, lazy-evaluated or encoded fields. Such fields should be calculated lazily before writing them to a stream. To use lazy evaluation just declare the value of such field as Closure instance.

Here is an example of length field calculation for the Kafka's Record class:


All versions of binary-protocol with dependencies

PHP Build Version
Package Version
Requires php Version ~7.1
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package alpari/binary-protocol contains the following files

Loading the files please wait ....