From 6a5bcaa754fa8ece15658d8542602cd7b846d00c Mon Sep 17 00:00:00 2001 From: Aditya Agarwal Date: Tue, 6 Feb 2007 02:50:56 +0000 Subject: [PATCH] -- Protocol and transport factories now wrap around a single protocol/transport Summary: - This is an analagous to the C++ change made in r31441 Reviewed By: slee git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664977 13f79535-47bb-0310-9956-ffa450edef68 --- lib/php/src/protocol/TBinaryProtocol.php | 39 ++++++++++++------------ lib/php/src/protocol/TProtocol.php | 38 +++++++---------------- 2 files changed, 30 insertions(+), 47 deletions(-) diff --git a/lib/php/src/protocol/TBinaryProtocol.php b/lib/php/src/protocol/TBinaryProtocol.php index 7684f5fc..e9ea3b86 100644 --- a/lib/php/src/protocol/TBinaryProtocol.php +++ b/lib/php/src/protocol/TBinaryProtocol.php @@ -1,4 +1,4 @@ -outputTransport_->write($data, 1); + $this->trans_->write($data, 1); return 1; } public function writeByte($value) { $data = pack('c', $value); - $this->outputTransport_->write($data, 1); + $this->trans_->write($data, 1); return 1; } public function writeI16($value) { $data = pack('n', $value); - $this->outputTransport_->write($data, 2); + $this->trans_->write($data, 2); return 2; } public function writeI32($value) { $data = pack('N', $value); - $this->outputTransport_->write($data, 4); + $this->trans_->write($data, 4); return 4; } @@ -136,13 +136,13 @@ class TBinaryProtocol extends TProtocol { $data = pack('N2', $hi, $lo); } - $this->outputTransport_->write($data, 8); + $this->trans_->write($data, 8); return 8; } public function writeDouble($value) { $data = pack('d', $value); - $this->outputTransport_->write(strrev($data), 8); + $this->trans_->write(strrev($data), 8); return 8; } @@ -150,7 +150,7 @@ class TBinaryProtocol extends TProtocol { $len = strlen($value); $result = $this->writeI32($len); if ($len) { - $this->outputTransport_->write($value, $len); + $this->trans_->write($value, $len); } return $result + $len; } @@ -221,21 +221,21 @@ class TBinaryProtocol extends TProtocol { } public function readBool(&$value) { - $data = $this->inputTransport_->readAll(1); + $data = $this->trans_->readAll(1); $arr = unpack('c', $data); $value = $arr[1] == 1; return 1; } public function readByte(&$value) { - $data = $this->inputTransport_->readAll(1); + $data = $this->trans_->readAll(1); $arr = unpack('c', $data); $value = $arr[1]; return 1; } public function readI16(&$value) { - $data = $this->inputTransport_->readAll(2); + $data = $this->trans_->readAll(2); $arr = unpack('n', $data); $value = $arr[1]; if ($value > 0x7fff) { @@ -245,7 +245,7 @@ class TBinaryProtocol extends TProtocol { } public function readI32(&$value) { - $data = $this->inputTransport_->readAll(4); + $data = $this->trans_->readAll(4); $arr = unpack('N', $data); $value = $arr[1]; if ($value > 0x7fffffff) { @@ -255,7 +255,7 @@ class TBinaryProtocol extends TProtocol { } public function readI64(&$value) { - $data = $this->inputTransport_->readAll(8); + $data = $this->trans_->readAll(8); $arr = unpack('N2', $data); @@ -315,7 +315,7 @@ class TBinaryProtocol extends TProtocol { } public function readDouble(&$value) { - $data = strrev($this->inputTransport_->readAll(8)); + $data = strrev($this->trans_->readAll(8)); $arr = unpack('d', $data); $value = $arr[1]; return 8; @@ -324,7 +324,7 @@ class TBinaryProtocol extends TProtocol { public function readString(&$value) { $result = $this->readI32($len); if ($len) { - $value = $this->inputTransport_->readAll($len); + $value = $this->trans_->readAll($len); } else { $value = ''; } @@ -336,9 +336,8 @@ class TBinaryProtocol extends TProtocol { * Binary Protocol Factory */ class TBinaryProtocolFactory implements TProtocolFactory { - public function getIOProtocols($itrans, $otrans) { - $prot = new TBinaryProtocol($itrans, $otrans); - return array($prot, $prot); + public function getProtocol($trans) { + return new TBinaryProtocol($trans); } } diff --git a/lib/php/src/protocol/TProtocol.php b/lib/php/src/protocol/TProtocol.php index eb150e37..95196041 100644 --- a/lib/php/src/protocol/TProtocol.php +++ b/lib/php/src/protocol/TProtocol.php @@ -6,6 +6,7 @@ * * @package thrift.protocol * @author Mark Slee + * @author Aditya Agarwal */ /** @@ -45,43 +46,26 @@ class TMessageType { abstract class TProtocol { /** - * Input transport + * Underlying transport * * @var TTransport */ - protected $inputTransport_; - - /** - * Output transport - * - * @var TTransport - */ - protected $outputTransport_; + protected $trans_; /** * Constructor */ - protected function __construct($in, $out=null) { - $this->inputTransport_ = $in; - $this->outputTransport_ = $out ? $out : $in; - } - - /** - * Accessor for input - * - * @return TTransport - */ - public function getInputTransport() { - return $this->inputTransport_; + protected function __construct($trans) { + $this->trans_ = $trans; } /** - * Accessor for output + * Accessor for transport * * @return TTransport */ - public function getOutputTransport() { - return $this->outputTransport_; + public function getTransport() { + return $this->trans_; } /** @@ -373,11 +357,11 @@ abstract class TProtocol { */ interface TProtocolFactory { /** - * Build input and output protocols from the given transports. + * Build a protocol from the base transport * - * @return array Two elements, (iprot, oprot) + * @return TProtcol protocol */ - public function getIOProtocols($itrans, $otrans); + public function getProtocol($trans); } -- 2.17.1