diff options
author | Armen Baghumian <armen@vardump.org> | 2016-03-14 17:37:22 +1100 |
---|---|---|
committer | Armen Baghumian <abaghumian@noggin.com.au> | 2016-03-29 14:56:09 +1100 |
commit | 28a3c939e7f2083b79254ff90cfde77e51908bc8 (patch) | |
tree | 9fcb81f9211f0e7a9c3589b53617dbbf5dbab3c2 /php | |
parent | a649cb7db568a20d5634752d56620c9567c4a242 (diff) | |
download | flatbuffers-28a3c939e7f2083b79254ff90cfde77e51908bc8.tar.gz flatbuffers-28a3c939e7f2083b79254ff90cfde77e51908bc8.tar.bz2 flatbuffers-28a3c939e7f2083b79254ff90cfde77e51908bc8.zip |
Implement __vector_as_bytes and methods to get [ubyte] efficiently
Currently in order to get a value type of [ubyte] in PHP, iteration is
necessary which is not efficient. Helper __vector_as_bytes has been
implemented in order to return the byte arrays in PHP efficiently.
Appropriate methods also been added to use aforementioned method to return
the byte array. (e.g. get*Bytes()).
The reason the methods are named get*Bytes() and not for instance
get*ByteArray() is the fact that PHP doesn't support byte arrays and the
binary safe string implementation in PHP is used to simulate byte arrays
and since there is chance for PHP users to confuse this with PHP arrays
the name get*Bytes() has been chosen.
In the future __vector_as_bytebuffer() method can also be implemented to
return PHP implementation of ByteBuffer.
Diffstat (limited to 'php')
-rw-r--r-- | php/Table.php | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/php/Table.php b/php/Table.php index 7f611456..6f917c1a 100644 --- a/php/Table.php +++ b/php/Table.php @@ -89,9 +89,15 @@ abstract class Table return $offset + $this->bb->getInt($offset) + Constants::SIZEOF_INT; } -// protected function __vector_as_bytebuffer($vector_offset, $elem_size) -// { -// } + protected function __vector_as_bytes($vector_offset, $elem_size=1) + { + $o = $this->__offset($vector_offset); + if ($o == 0) { + return null; + } + + return substr($this->bb->_buffer, $this->__vector($o), $this->__vector_len($o) * $elem_size); + } /** * @param Table $table |