TProtocolDecorator.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. *
  20. * @package thrift.protocol
  21. */
  22. namespace Thrift\Protocol;
  23. use Thrift\Exception\TException;
  24. /**
  25. * <code>TProtocolDecorator</code> forwards all requests to an enclosed
  26. * <code>TProtocol</code> instance, providing a way to author concise
  27. * concrete decorator subclasses. While it has no abstract methods, it
  28. * is marked abstract as a reminder that by itself, it does not modify
  29. * the behaviour of the enclosed <code>TProtocol</code>.
  30. *
  31. * @package Thrift\Protocol
  32. */
  33. abstract class TProtocolDecorator extends TProtocol
  34. {
  35. /**
  36. * Instance of protocol, to which all operations will be forwarded.
  37. *
  38. * @var TProtocol
  39. */
  40. private $concreteProtocol_;
  41. /**
  42. * Constructor of <code>TProtocolDecorator</code> class.
  43. * Encloses the specified protocol.
  44. *
  45. * @param TProtocol $protocol All operations will be forward to this instance. Must be non-null.
  46. */
  47. protected function __construct(TProtocol $protocol)
  48. {
  49. parent::__construct($protocol->getTransport());
  50. $this->concreteProtocol_ = $protocol;
  51. }
  52. /**
  53. * Writes the message header.
  54. *
  55. * @param string $name Function name
  56. * @param int $type message type TMessageType::CALL or TMessageType::REPLY
  57. * @param int $seqid The sequence id of this message
  58. */
  59. public function writeMessageBegin($name, $type, $seqid)
  60. {
  61. return $this->concreteProtocol_->writeMessageBegin($name, $type, $seqid);
  62. }
  63. /**
  64. * Closes the message.
  65. */
  66. public function writeMessageEnd()
  67. {
  68. return $this->concreteProtocol_->writeMessageEnd();
  69. }
  70. /**
  71. * Writes a struct header.
  72. *
  73. * @param string $name Struct name
  74. *
  75. * @throws TException on write error
  76. * @return int How many bytes written
  77. */
  78. public function writeStructBegin($name)
  79. {
  80. return $this->concreteProtocol_->writeStructBegin($name);
  81. }
  82. /**
  83. * Close a struct.
  84. *
  85. * @throws TException on write error
  86. * @return int How many bytes written
  87. */
  88. public function writeStructEnd()
  89. {
  90. return $this->concreteProtocol_->writeStructEnd();
  91. }
  92. public function writeFieldBegin($fieldName, $fieldType, $fieldId)
  93. {
  94. return $this->concreteProtocol_->writeFieldBegin($fieldName, $fieldType, $fieldId);
  95. }
  96. public function writeFieldEnd()
  97. {
  98. return $this->concreteProtocol_->writeFieldEnd();
  99. }
  100. public function writeFieldStop()
  101. {
  102. return $this->concreteProtocol_->writeFieldStop();
  103. }
  104. public function writeMapBegin($keyType, $valType, $size)
  105. {
  106. return $this->concreteProtocol_->writeMapBegin($keyType, $valType, $size);
  107. }
  108. public function writeMapEnd()
  109. {
  110. return $this->concreteProtocol_->writeMapEnd();
  111. }
  112. public function writeListBegin($elemType, $size)
  113. {
  114. return $this->concreteProtocol_->writeListBegin($elemType, $size);
  115. }
  116. public function writeListEnd()
  117. {
  118. return $this->concreteProtocol_->writeListEnd();
  119. }
  120. public function writeSetBegin($elemType, $size)
  121. {
  122. return $this->concreteProtocol_->writeSetBegin($elemType, $size);
  123. }
  124. public function writeSetEnd()
  125. {
  126. return $this->concreteProtocol_->writeSetEnd();
  127. }
  128. public function writeBool($bool)
  129. {
  130. return $this->concreteProtocol_->writeBool($bool);
  131. }
  132. public function writeByte($byte)
  133. {
  134. return $this->concreteProtocol_->writeByte($byte);
  135. }
  136. public function writeI16($i16)
  137. {
  138. return $this->concreteProtocol_->writeI16($i16);
  139. }
  140. public function writeI32($i32)
  141. {
  142. return $this->concreteProtocol_->writeI32($i32);
  143. }
  144. public function writeI64($i64)
  145. {
  146. return $this->concreteProtocol_->writeI64($i64);
  147. }
  148. public function writeDouble($dub)
  149. {
  150. return $this->concreteProtocol_->writeDouble($dub);
  151. }
  152. public function writeString($str)
  153. {
  154. return $this->concreteProtocol_->writeString($str);
  155. }
  156. /**
  157. * Reads the message header
  158. *
  159. * @param string $name Function name
  160. * @param int $type message type TMessageType::CALL or TMessageType::REPLY
  161. * @param int $seqid The sequence id of this message
  162. */
  163. public function readMessageBegin(&$name, &$type, &$seqid)
  164. {
  165. return $this->concreteProtocol_->readMessageBegin($name, $type, $seqid);
  166. }
  167. /**
  168. * Read the close of message
  169. */
  170. public function readMessageEnd()
  171. {
  172. return $this->concreteProtocol_->readMessageEnd();
  173. }
  174. public function readStructBegin(&$name)
  175. {
  176. return $this->concreteProtocol_->readStructBegin($name);
  177. }
  178. public function readStructEnd()
  179. {
  180. return $this->concreteProtocol_->readStructEnd();
  181. }
  182. public function readFieldBegin(&$name, &$fieldType, &$fieldId)
  183. {
  184. return $this->concreteProtocol_->readFieldBegin($name, $fieldType, $fieldId);
  185. }
  186. public function readFieldEnd()
  187. {
  188. return $this->concreteProtocol_->readFieldEnd();
  189. }
  190. public function readMapBegin(&$keyType, &$valType, &$size)
  191. {
  192. $this->concreteProtocol_->readMapBegin($keyType, $valType, $size);
  193. }
  194. public function readMapEnd()
  195. {
  196. return $this->concreteProtocol_->readMapEnd();
  197. }
  198. public function readListBegin(&$elemType, &$size)
  199. {
  200. $this->concreteProtocol_->readListBegin($elemType, $size);
  201. }
  202. public function readListEnd()
  203. {
  204. return $this->concreteProtocol_->readListEnd();
  205. }
  206. public function readSetBegin(&$elemType, &$size)
  207. {
  208. return $this->concreteProtocol_->readSetBegin($elemType, $size);
  209. }
  210. public function readSetEnd()
  211. {
  212. return $this->concreteProtocol_->readSetEnd();
  213. }
  214. public function readBool(&$bool)
  215. {
  216. return $this->concreteProtocol_->readBool($bool);
  217. }
  218. public function readByte(&$byte)
  219. {
  220. return $this->concreteProtocol_->readByte($byte);
  221. }
  222. public function readI16(&$i16)
  223. {
  224. return $this->concreteProtocol_->readI16($i16);
  225. }
  226. public function readI32(&$i32)
  227. {
  228. return $this->concreteProtocol_->readI32($i32);
  229. }
  230. public function readI64(&$i64)
  231. {
  232. return $this->concreteProtocol_->readI64($i64);
  233. }
  234. public function readDouble(&$dub)
  235. {
  236. return $this->concreteProtocol_->readDouble($dub);
  237. }
  238. public function readString(&$str)
  239. {
  240. return $this->concreteProtocol_->readString($str);
  241. }
  242. }