PHP Classes
elePHPant
Icontem

Memory Efficient Serialization Library: Store and retrieve data types in binary files

Recommend this page to a friend!
  Info   View files Documentation   View files View files (12)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2016-09-05 (23 days ago) RSS 2.0 feedNot enough user ratingsTotal: 107 This week: 1All time: 8,402 This week: 872Up
Version License PHP version Categories
flatbuffers 0.0.1Free To Use But R...5.4PHP 5, Data types
Description Author

This package can store and retrieve data types in binary files.

It can serialize values of different types into streams of binary data.

The package can also retrieve the data types previously serialized as binary data.

The serialized data is stored in buffer string variable.

Picture of Lukas Mestan
  Performance   Level  
Name: Lukas Mestan is available for providing paid consulting. Contact Lukas Mestan .
Classes: 8 packages by
Country: Slovak Republic Slovak Republic
Age: 35
All time rank: 8904 in Slovak Republic Slovak Republic
Week rank: 474 Up3 in Slovak Republic Slovak Republic Up
Innovation award
Innovation award
Nominee: 1x

Details

PHP Memory Efficient Serialization Library

Build Status

FlatBuffers is a serialization library for games and other memory constrained apps.

FlatBuffers allows you to directly access serialized data without unpacking/parsing it first, while still having great forwards/backwards compatibility.

FlatBuffers can be built for many different systems (Android, Windows, OS X, Linux)

For testing only

Composer

{
    "repositories": [
        {
            "url": "https://github.com/arzzen/php-flatbuffers.git",
            "type": "git"
        }
    ],
    "require": {
        "arzzen/php-flatbuffers": "dev-master"
    }
}

Test:

use FlatBuffers\Table;
use FlatBuffers\FlatBufferBuilder;
use FlatBuffers\ByteBuffer;
use FlatBuffers\Constants;

class StringWrapper extends Table implements Constants
{
	
	private $fbb;
	
	public function __construct(FlatBufferBuilder $flatBufferBuilder)
	{
		$this->fbb = $flatBufferBuilder;
	}
	
	public function init(ByteBuffer $byteBuffer)
	{
		$this->bb = $byteBuffer;
		$this->bb_pos = $this->bb->getInt($this->bb->getPosition()) + $this->bb->getPosition();
		
		return $this;
	}
	
	public function getString($slot = 0)
	{
		$vtable_offset = self::SIZEOF_INT + ($slot * 2); 
		
		$vtable = $this->bb_pos - $this->bb->getInt($this->bb_pos);
		
		$offset = $vtable_offset < $this->bb->getShort($vtable) ? $this->bb->getShort($vtable + $vtable_offset) : 0;
		
		$offset += $this->bb_pos + $this->bb->getInt($offset + $this->bb_pos);
		$len = $this->bb->getInt($offset);
		$startPos = $offset + self::SIZEOF_INT;
		$_string = substr($this->bb->_buffer, $startPos, $len);

		return ($offset != 0 ? $_string : null);
	}
	
	public function createString($value)
	{
		return $this->fbb->createString($value);
	}
	
	public function addString($slot, $str)
	{
		$this->fbb->addOffsetX($slot, $str, 0);
	}

	public function dataBuffer()
	{
		return $this->fbb->dataBuffer();
	}
	
	public function startObject($numfields)
	{
		$this->fbb->startObject($numfields);
	}
	
	public function endObject()
	{
		return $this->fbb->endObject();
	}
	
	public function finish($root_table, $identifier = NULL)
	{
		$this->fbb->finish($root_table, $identifier);
	}
	
}


$flatBufferBuilder = new FlatBufferBuilder(1);
$stringWrapper = new StringWrapper($flatBufferBuilder);

// set string
$firstText = $stringWrapper->createString('first_value');
$secondText = $stringWrapper->createString('second_value');

$stringWrapper->startObject(25);
$stringWrapper->addString(2, $firstText);
$stringWrapper->addString(3, $secondText);
$stringWrapper->finish($stringWrapper->endObject());

// get string
$stringWrapper->init($stringWrapper->dataBuffer());

echo $stringWrapper->getString(2);
echo $stringWrapper->getString(3);

  Files folder image Files  
File Role Description
Files folder imagesrc (5 files)
Files folder imagetests (1 file)
Accessible without login Plain text file .gitignore Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Auxiliary data

  Files folder image Files  /  src  
File Role Description
  Plain text file ByteBuffer.php Class Class source
  Plain text file Constants.php Class Class source
  Plain text file FlatBufferBuilder.php Class Class source
  Plain text file Struct.php Class Class source
  Plain text file Table.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Accessible without login Plain text file FlatBuffersTest.php Test Unit test script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:107
This week:1
All time:8,402
This week:872Up