PHP Classes

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

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 125 All time: 9,448 This week: 455Up
Version License PHP version Categories
flatbuffers 0.0.1Free To Use But R...5.4PHP 5, Data types
Description 

Authors

Shuhei Tanuma
Lukas Mestan


Contributor

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  
Innovation award
Innovation award
Nominee: 1x

 

Documentation

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 (13)  
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 CODE_OF_CONDUCT.md 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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:125
This week:0
All time:9,448
This week:455Up