Skip to content
This repository has been archived by the owner on Mar 27, 2019. It is now read-only.

Commit

Permalink
Added buffering hints to all transforms.
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed May 13, 2014
1 parent 58e846a commit c562cf3
Show file tree
Hide file tree
Showing 36 changed files with 312 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .travis.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
akvF272KZeVmQD6awMN6yn+lMRoCpRhhTDOrNahI0yshv57fqbpvOoHRKXv6WjbwKYIb0DaKrd0utbKIbtXDqdExJbUsfoGZojALrSrmWTJk2bVOCUVz1icFTUM/MIphglIupfmXQAy22R8jLkbVlQKcEQ1JjLZtLkluBjQUpBU=
ENwfQv8SMFAoIazNkBk5xFatEg3MptXedUnPfUcMwMV3Ohez/3//maXhVC+Mrp0EXjolswOzbWeF0GhV/BEgVs3dtQcLVgd0HGkRnWrlutkz9NS9ViTC2cJ49TwA0bEUbX1Yod6tA3fwsHAi9k0WxmARNMGknObC6AAM9zXsINQ=
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ matrix:
env:
global:
- ARCHER_PUBLISH_VERSION=5.5
- secure: "akvF272KZeVmQD6awMN6yn+lMRoCpRhhTDOrNahI0yshv57fqbpvOoHRKXv6WjbwKYIb0DaKrd0utbKIbtXDqdExJbUsfoGZojALrSrmWTJk2bVOCUVz1icFTUM/MIphglIupfmXQAy22R8jLkbVlQKcEQ1JjLZtLkluBjQUpBU="
- secure: "ENwfQv8SMFAoIazNkBk5xFatEg3MptXedUnPfUcMwMV3Ohez/3//maXhVC+Mrp0EXjolswOzbWeF0GhV/BEgVs3dtQcLVgd0HGkRnWrlutkz9NS9ViTC2cJ49TwA0bEUbX1Yod6tA3fwsHAi9k0WxmARNMGknObC6AAM9zXsINQ="

install:
- ./.travis.install
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
],
"require": {
"php": ">=5.3",
"eloquent/confetti": "~0.2.0",
"eloquent/confetti": "~0.3.0",
"evenement/evenement": ">=1,<3",
"icecave/isolator": "~2",
"react/stream": ">=0.3,<0.5"
Expand Down
21 changes: 18 additions & 3 deletions src/Base16/Base16DecodeTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
namespace Eloquent\Endec\Base16;

use Eloquent\Confetti\AbstractTransform;
use Eloquent\Confetti\TransformInterface;
use Eloquent\Confetti\BufferedTransformInterface;
use Eloquent\Endec\Exception\InvalidEncodedDataException;

/**
* Decodes data using base16 (hexadecimal) encoding.
*
* @link http://tools.ietf.org/html/rfc4648#section-8
*/
class Base16DecodeTransform extends AbstractTransform
class Base16DecodeTransform extends AbstractTransform implements
BufferedTransformInterface
{
/**
* Get the static instance of this transform.
*
* @return TransformInterface The transform.
* @return BufferedTransformInterface The transform.
*/
public static function instance()
{
Expand Down Expand Up @@ -76,5 +77,19 @@ public function transform($data, &$context, $isEnd = false)
return array(pack('H*', $consumedData), $consume, null);
}

/**
* Get the buffer size.
*
* This method is used to determine how much input is typically required
* before output can be produced. This can provide performance benefits by
* avoiding excessive method calls.
*
* @return integer The buffer size.
*/
public function bufferSize()
{
return 2;
}

private static $instance;
}
20 changes: 17 additions & 3 deletions src/Base16/Base16EncodeTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@

namespace Eloquent\Endec\Base16;

use Eloquent\Confetti\TransformInterface;
use Eloquent\Confetti\BufferedTransformInterface;

/**
* Encodes data using base16 (hexadecimal) encoding.
*
* @link http://tools.ietf.org/html/rfc4648#section-8
*/
class Base16EncodeTransform implements TransformInterface
class Base16EncodeTransform implements BufferedTransformInterface
{
/**
* Get the static instance of this transform.
*
* @return TransformInterface The transform.
* @return BufferedTransformInterface The transform.
*/
public static function instance()
{
Expand Down Expand Up @@ -60,5 +60,19 @@ public function transform($data, &$context, $isEnd = false)
return array(strtoupper(bin2hex($data)), strlen($data), null);
}

/**
* Get the buffer size.
*
* This method is used to determine how much input is typically required
* before output can be produced. This can provide performance benefits by
* avoiding excessive method calls.
*
* @return integer The buffer size.
*/
public function bufferSize()
{
return 1;
}

private static $instance;
}
19 changes: 17 additions & 2 deletions src/Base32/AbstractBase32DecodeTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Eloquent\Endec\Base32;

use Eloquent\Confetti\TransformInterface;
use Eloquent\Confetti\BufferedTransformInterface;
use Eloquent\Endec\Exception\EncodingExceptionInterface;
use Eloquent\Endec\Exception\InvalidEncodedDataException;

Expand All @@ -20,7 +20,8 @@
*
* @link http://tools.ietf.org/html/rfc4648#section-6
*/
abstract class AbstractBase32DecodeTransform implements TransformInterface
abstract class AbstractBase32DecodeTransform implements
BufferedTransformInterface
{
/**
* Transform the supplied data.
Expand Down Expand Up @@ -115,6 +116,20 @@ public function transform($data, &$context, $isEnd = false)
return array($output, $consumed + $paddedLength - $length, null);
}

/**
* Get the buffer size.
*
* This method is used to determine how much input is typically required
* before output can be produced. This can provide performance benefits by
* avoiding excessive method calls.
*
* @return integer The buffer size.
*/
public function bufferSize()
{
return 8;
}

private function map2($a, $b)
{
return chr($a << 3 | $b >> 2);
Expand Down
19 changes: 17 additions & 2 deletions src/Base32/AbstractBase32EncodeTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

namespace Eloquent\Endec\Base32;

use Eloquent\Confetti\TransformInterface;
use Eloquent\Confetti\BufferedTransformInterface;

/**
* An abstract base class for implementing base32 encode transforms.
*
* @link http://tools.ietf.org/html/rfc4648#section-6
*/
abstract class AbstractBase32EncodeTransform implements TransformInterface
abstract class AbstractBase32EncodeTransform implements
BufferedTransformInterface
{
/**
* Construct a new base32 encode transform.
Expand Down Expand Up @@ -100,6 +101,20 @@ public function transform($data, &$context, $isEnd = false)
return array($output, $consumed, null);
}

/**
* Get the buffer size.
*
* This method is used to determine how much input is typically required
* before output can be produced. This can provide performance benefits by
* avoiding excessive method calls.
*
* @return integer The buffer size.
*/
public function bufferSize()
{
return 5;
}

private function map1($a)
{
return $this->alphabet[($a >> 3)] .
Expand Down
4 changes: 2 additions & 2 deletions src/Base32/Base32DecodeTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Eloquent\Endec\Base32;

use Eloquent\Confetti\TransformInterface;
use Eloquent\Confetti\BufferedTransformInterface;
use Eloquent\Endec\Exception\EncodingExceptionInterface;
use Eloquent\Endec\Exception\InvalidEncodedDataException;

Expand All @@ -25,7 +25,7 @@ class Base32DecodeTransform extends AbstractBase32DecodeTransform
/**
* Get the static instance of this transform.
*
* @return TransformInterface The transform.
* @return BufferedTransformInterface The transform.
*/
public static function instance()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Base32/Base32EncodeTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Eloquent\Endec\Base32;

use Eloquent\Confetti\TransformInterface;
use Eloquent\Confetti\BufferedTransformInterface;

/**
* Encodes data using base32 encoding.
Expand All @@ -23,7 +23,7 @@ class Base32EncodeTransform extends AbstractBase32EncodeTransform
/**
* Get the static instance of this transform.
*
* @return TransformInterface The transform.
* @return BufferedTransformInterface The transform.
*/
public static function instance()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Base32/Base32HexDecodeTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Eloquent\Endec\Base32;

use Eloquent\Confetti\TransformInterface;
use Eloquent\Confetti\BufferedTransformInterface;
use Eloquent\Endec\Exception\EncodingExceptionInterface;
use Eloquent\Endec\Exception\InvalidEncodedDataException;

Expand All @@ -25,7 +25,7 @@ class Base32HexDecodeTransform extends AbstractBase32DecodeTransform
/**
* Get the static instance of this transform.
*
* @return TransformInterface The transform.
* @return BufferedTransformInterface The transform.
*/
public static function instance()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Base32/Base32HexEncodeTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Eloquent\Endec\Base32;

use Eloquent\Confetti\TransformInterface;
use Eloquent\Confetti\BufferedTransformInterface;

/**
* Encodes data using base32hex encoding.
Expand All @@ -23,7 +23,7 @@ class Base32HexEncodeTransform extends AbstractBase32EncodeTransform
/**
* Get the static instance of this transform.
*
* @return TransformInterface The transform.
* @return BufferedTransformInterface The transform.
*/
public static function instance()
{
Expand Down
21 changes: 18 additions & 3 deletions src/Base64/Base64DecodeTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
namespace Eloquent\Endec\Base64;

use Eloquent\Confetti\AbstractTransform;
use Eloquent\Confetti\TransformInterface;
use Eloquent\Confetti\BufferedTransformInterface;
use Eloquent\Endec\Exception\InvalidEncodedDataException;

/**
* Decodes data using base64 encoding.
*
* @link http://tools.ietf.org/html/rfc4648#section-4
*/
class Base64DecodeTransform extends AbstractTransform
class Base64DecodeTransform extends AbstractTransform implements
BufferedTransformInterface
{
/**
* Get the static instance of this transform.
*
* @return TransformInterface The transform.
* @return BufferedTransformInterface The transform.
*/
public static function instance()
{
Expand Down Expand Up @@ -85,5 +86,19 @@ public function transform($data, &$context, $isEnd = false)
return array($outputBuffer, $consume, null);
}

/**
* Get the buffer size.
*
* This method is used to determine how much input is typically required
* before output can be produced. This can provide performance benefits by
* avoiding excessive method calls.
*
* @return integer The buffer size.
*/
public function bufferSize()
{
return 4;
}

private static $instance;
}
21 changes: 18 additions & 3 deletions src/Base64/Base64EncodeTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
namespace Eloquent\Endec\Base64;

use Eloquent\Confetti\AbstractTransform;
use Eloquent\Confetti\TransformInterface;
use Eloquent\Confetti\BufferedTransformInterface;

/**
* Encodes data using base64 encoding.
*
* @link http://tools.ietf.org/html/rfc4648#section-4
*/
class Base64EncodeTransform extends AbstractTransform
class Base64EncodeTransform extends AbstractTransform implements
BufferedTransformInterface
{
/**
* Get the static instance of this transform.
*
* @return TransformInterface The transform.
* @return BufferedTransformInterface The transform.
*/
public static function instance()
{
Expand Down Expand Up @@ -66,5 +67,19 @@ public function transform($data, &$context, $isEnd = false)
return array(base64_encode(substr($data, 0, $consume)), $consume, null);
}

/**
* Get the buffer size.
*
* This method is used to determine how much input is typically required
* before output can be produced. This can provide performance benefits by
* avoiding excessive method calls.
*
* @return integer The buffer size.
*/
public function bufferSize()
{
return 3;
}

private static $instance;
}
8 changes: 2 additions & 6 deletions src/Base64/Base64MimeDecodeTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Eloquent\Endec\Base64;

use Eloquent\Confetti\TransformInterface;
use Eloquent\Confetti\BufferedTransformInterface;
use Eloquent\Endec\Exception\InvalidEncodedDataException;

/**
Expand All @@ -24,7 +24,7 @@ class Base64MimeDecodeTransform extends Base64DecodeTransform
/**
* Get the static instance of this transform.
*
* @return TransformInterface The transform.
* @return BufferedTransformInterface The transform.
*/
public static function instance()
{
Expand Down Expand Up @@ -98,10 +98,6 @@ public function transform($data, &$context, $isEnd = false)
$context
);

if (null !== $error) {
return array('', 0, $error);
}

$output .= $thisOutput;

if ($consumed === strlen($buffer)) {
Expand Down
Loading

0 comments on commit c562cf3

Please sign in to comment.