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 23namespace Thrift\Protocol; 24 25use Thrift\Exception\TException; 26 27/** 28 * <code>TProtocolDecorator</code> forwards all requests to an enclosed 29 * <code>TProtocol</code> instance, providing a way to author concise 30 * concrete decorator subclasses. While it has no abstract methods, it 31 * is marked abstract as a reminder that by itself, it does not modify 32 * the behaviour of the enclosed <code>TProtocol</code>. 33 * 34 * @package Thrift\Protocol 35 */ 36abstract class TProtocolDecorator extends TProtocol 37{ 38 /** 39 * Instance of protocol, to which all operations will be forwarded. 40 * 41 * @var TProtocol 42 */ 43 private $concreteProtocol_; 44 45 /** 46 * Constructor of <code>TProtocolDecorator</code> class. 47 * Encloses the specified protocol. 48 * 49 * @param TProtocol $protocol All operations will be forward to this instance. Must be non-null. 50 */ 51 protected function __construct(TProtocol $protocol) 52 { 53 parent::__construct($protocol->getTransport()); 54 $this->concreteProtocol_ = $protocol; 55 } 56 57 /** 58 * Writes the message header. 59 * 60 * @param string $name Function name 61 * @param int $type message type TMessageType::CALL or TMessageType::REPLY 62 * @param int $seqid The sequence id of this message 63 */ 64 public function writeMessageBegin($name, $type, $seqid) 65 { 66 return $this->concreteProtocol_->writeMessageBegin($name, $type, $seqid); 67 } 68 69 /** 70 * Closes the message. 71 */ 72 public function writeMessageEnd() 73 { 74 return $this->concreteProtocol_->writeMessageEnd(); 75 } 76 77 /** 78 * Writes a struct header. 79 * 80 * @param string $name Struct name 81 * 82 * @throws TException on write error 83 * @return int How many bytes written 84 */ 85 public function writeStructBegin($name) 86 { 87 return $this->concreteProtocol_->writeStructBegin($name); 88 } 89 90 /** 91 * Close a struct. 92 * 93 * @throws TException on write error 94 * @return int How many bytes written 95 */ 96 public function writeStructEnd() 97 { 98 return $this->concreteProtocol_->writeStructEnd(); 99 } 100 101 public function writeFieldBegin($fieldName, $fieldType, $fieldId) 102 { 103 return $this->concreteProtocol_->writeFieldBegin($fieldName, $fieldType, $fieldId); 104 } 105 106 public function writeFieldEnd() 107 { 108 return $this->concreteProtocol_->writeFieldEnd(); 109 } 110 111 public function writeFieldStop() 112 { 113 return $this->concreteProtocol_->writeFieldStop(); 114 } 115 116 public function writeMapBegin($keyType, $valType, $size) 117 { 118 return $this->concreteProtocol_->writeMapBegin($keyType, $valType, $size); 119 } 120 121 public function writeMapEnd() 122 { 123 return $this->concreteProtocol_->writeMapEnd(); 124 } 125 126 public function writeListBegin($elemType, $size) 127 { 128 return $this->concreteProtocol_->writeListBegin($elemType, $size); 129 } 130 131 public function writeListEnd() 132 { 133 return $this->concreteProtocol_->writeListEnd(); 134 } 135 136 public function writeSetBegin($elemType, $size) 137 { 138 return $this->concreteProtocol_->writeSetBegin($elemType, $size); 139 } 140 141 public function writeSetEnd() 142 { 143 return $this->concreteProtocol_->writeSetEnd(); 144 } 145 146 public function writeBool($bool) 147 { 148 return $this->concreteProtocol_->writeBool($bool); 149 } 150 151 public function writeByte($byte) 152 { 153 return $this->concreteProtocol_->writeByte($byte); 154 } 155 156 public function writeI16($i16) 157 { 158 return $this->concreteProtocol_->writeI16($i16); 159 } 160 161 public function writeI32($i32) 162 { 163 return $this->concreteProtocol_->writeI32($i32); 164 } 165 166 public function writeI64($i64) 167 { 168 return $this->concreteProtocol_->writeI64($i64); 169 } 170 171 public function writeDouble($dub) 172 { 173 return $this->concreteProtocol_->writeDouble($dub); 174 } 175 176 public function writeString($str) 177 { 178 return $this->concreteProtocol_->writeString($str); 179 } 180 181 /** 182 * Reads the message header 183 * 184 * @param string $name Function name 185 * @param int $type message type TMessageType::CALL or TMessageType::REPLY 186 * @param int $seqid The sequence id of this message 187 */ 188 public function readMessageBegin(&$name, &$type, &$seqid) 189 { 190 return $this->concreteProtocol_->readMessageBegin($name, $type, $seqid); 191 } 192 193 /** 194 * Read the close of message 195 */ 196 public function readMessageEnd() 197 { 198 return $this->concreteProtocol_->readMessageEnd(); 199 } 200 201 public function readStructBegin(&$name) 202 { 203 return $this->concreteProtocol_->readStructBegin($name); 204 } 205 206 public function readStructEnd() 207 { 208 return $this->concreteProtocol_->readStructEnd(); 209 } 210 211 public function readFieldBegin(&$name, &$fieldType, &$fieldId) 212 { 213 return $this->concreteProtocol_->readFieldBegin($name, $fieldType, $fieldId); 214 } 215 216 public function readFieldEnd() 217 { 218 return $this->concreteProtocol_->readFieldEnd(); 219 } 220 221 public function readMapBegin(&$keyType, &$valType, &$size) 222 { 223 $this->concreteProtocol_->readMapBegin($keyType, $valType, $size); 224 } 225 226 public function readMapEnd() 227 { 228 return $this->concreteProtocol_->readMapEnd(); 229 } 230 231 public function readListBegin(&$elemType, &$size) 232 { 233 $this->concreteProtocol_->readListBegin($elemType, $size); 234 } 235 236 public function readListEnd() 237 { 238 return $this->concreteProtocol_->readListEnd(); 239 } 240 241 public function readSetBegin(&$elemType, &$size) 242 { 243 return $this->concreteProtocol_->readSetBegin($elemType, $size); 244 } 245 246 public function readSetEnd() 247 { 248 return $this->concreteProtocol_->readSetEnd(); 249 } 250 251 public function readBool(&$bool) 252 { 253 return $this->concreteProtocol_->readBool($bool); 254 } 255 256 public function readByte(&$byte) 257 { 258 return $this->concreteProtocol_->readByte($byte); 259 } 260 261 public function readI16(&$i16) 262 { 263 return $this->concreteProtocol_->readI16($i16); 264 } 265 266 public function readI32(&$i32) 267 { 268 return $this->concreteProtocol_->readI32($i32); 269 } 270 271 public function readI64(&$i64) 272 { 273 return $this->concreteProtocol_->readI64($i64); 274 } 275 276 public function readDouble(&$dub) 277 { 278 return $this->concreteProtocol_->readDouble($dub); 279 } 280 281 public function readString(&$str) 282 { 283 return $this->concreteProtocol_->readString($str); 284 } 285} 286