2017 © Pedro Peláez
 

library php-flatbuffers

PHP Memory Efficient Serialization Library - FlatBuffers

image

arzzen/php-flatbuffers

PHP Memory Efficient Serialization Library - FlatBuffers

  • Friday, January 12, 2018
  • by arzzen
  • Repository
  • 1 Watchers
  • 5 Stars
  • 16 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 2 Open issues
  • 6 Versions
  • 14 % Grown

The README.md

PHP Memory Efficient Serialization Library

Build Status, (*1)

FlatBuffers is a serialization library for games and other memory constrained apps., (*2)

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

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

For testing only, (*5)

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);

The Versions

12/01 2018

dev-master

9999999-dev https://github.com/arzzen/php-flatbuffers

PHP Memory Efficient Serialization Library - FlatBuffers

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

The Development Requires

php google serialize memory flatbuffers

14/09 2017

dev-add-code-of-conduct-1-1

dev-add-code-of-conduct-1-1 https://github.com/arzzen/php-flatbuffers

PHP Memory Efficient Serialization Library - FlatBuffers

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

The Development Requires

php google serialize memory flatbuffers

14/09 2017

dev-add-code-of-conduct-1

dev-add-code-of-conduct-1 https://github.com/arzzen/php-flatbuffers

PHP Memory Efficient Serialization Library - FlatBuffers

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

The Development Requires

php google serialize memory flatbuffers

07/01 2017

1.0.2

1.0.2.0 https://github.com/arzzen/php-flatbuffers

PHP Memory Efficient Serialization Library - FlatBuffers

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

The Development Requires

php google serialize memory flatbuffers

04/10 2016

1.0.1

1.0.1.0 https://github.com/arzzen/php-flatbuffers

PHP Memory Efficient Serialization Library - FlatBuffers

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

The Development Requires

php google serialize memory flatbuffers

03/09 2016

1.0.0

1.0.0.0 https://github.com/arzzen/php-flatbuffers

PHP Memory Efficient Serialization Library - FlatBuffers

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

The Development Requires

php google serialize memory flatbuffers