tars-extension document

Intrudoction

tars-extension is a php extension for high-performance tars package unpacking and tup encoding and decoding implemented in c, which is the basic dependency of the entire phptars.

Instruction

Like other php extensions, enter the extension directory to execute:

phpize
./configure
make
make test
make install

Modify the php.ini file to load the .so file. Use the php -m command to see if the extension is successfully installed.

Extension description

tars-extension extension does three main things:

  • All data structures of tars are mapped with extended types

  • Three complex types of tars are mapped with special extension types

  • Provides the ability to package, unpack, encode and decode tup and tars protocols

Mapping of basic types

When we need to identify specific variable types, we need to use these basic types, these types are constants, from 1-14.

Mapping of complex types

For the three basic types of vector, map, and struct, there are some special packaging and unpacking mechanisms, so special data types need to be introduced:

vector:

map:

struct:

Packing and encoding

As the core function of the extension, it is the ability to provide tars encoding and decoding and packaging and unpacking:

Packing

编码解码

For a richer use of packing and unpacking of different types of structures, please refer to tests/

tars2php (Automatically generate php class tools) Instructions for use

Refer to the tars2php module: Detailed description

Test case

phpunit

For common use of extensions, add test cases, located under /ext/testcases folder, You only need to execute php phpunit-4.8.36.phar test.php when testing to complete the execution of all test cases. Which covered:

  • All basic types of unpacking and coding tests

  • Simple struct type package unpacking and encoding test

  • Packaging and unpacking and encoding tests for simple vector types

  • Simple map type unpacking and encoding test

  • Packaging and encoding tests for complex vector types (including non-primitive data types)

  • Packaging and encoding tests for complex map types (including non-primitive data types)

  • Packaging and encoding tests for complex struct types (nested vectors and maps)

In addition, testTARSClient.php and testTARSServer.php are test cases where the client sends packets, the server unpacks and the server returns packets, and the client unpacks under the tars protocol (iVersion = 1).

Note that you need to download the phpunit executable file yourself, or use the pre-installed phpunit tool directly for unit testing.

phpt

After installing the extension, run make test

Last updated