Roger Meier | 21c0a85 | 2012-09-05 19:47:14 +0000 | [diff] [blame] | 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 | |
| 23 | namespace Thrift\Protocol; |
| 24 | |
Roger Meier | 21c0a85 | 2012-09-05 19:47:14 +0000 | [diff] [blame] | 25 | use Thrift\Transport\TBufferedTransport; |
| 26 | |
| 27 | /** |
| 28 | * Accelerated binary protocol: used in conjunction with the thrift_protocol |
| 29 | * extension for faster deserialization |
| 30 | */ |
Roger Thomas | 6fb5923 | 2014-11-04 10:09:23 +0000 | [diff] [blame] | 31 | class TBinaryProtocolAccelerated extends TBinaryProtocol |
| 32 | { |
Robert Lu | b03ca01 | 2018-01-18 19:06:39 +0800 | [diff] [blame] | 33 | public function __construct($trans, $strictRead = false, $strictWrite = true) |
| 34 | { |
| 35 | // If the transport doesn't implement putBack, wrap it in a |
| 36 | // TBufferedTransport (which does) |
Roger Thomas | 6fb5923 | 2014-11-04 10:09:23 +0000 | [diff] [blame] | 37 | |
Robert Lu | b03ca01 | 2018-01-18 19:06:39 +0800 | [diff] [blame] | 38 | // NOTE (t.heintz): This is very evil to do, because the TBufferedTransport may swallow bytes, which |
| 39 | // are then never written to the underlying transport. This happens precisely when a number of bytes |
| 40 | // less than the max buffer size (512 by default) is written to the transport and then flush() is NOT |
| 41 | // called. In that case the data stays in the writeBuffer of the transport, from where it can never be |
| 42 | // accessed again (for example through read()). |
| 43 | // |
| 44 | // Since the caller of this method does not know about the wrapping transport, this creates bugs which |
| 45 | // are very difficult to find. Hence the wrapping of a transport in a buffer should be left to the |
| 46 | // calling code. An interface could used to mandate the presence of the putBack() method in the transport. |
| 47 | // |
| 48 | // I am leaving this code in nonetheless, because there may be applications depending on this behavior. |
| 49 | // |
| 50 | // @see THRIFT-1579 |
Roger Thomas | 6fb5923 | 2014-11-04 10:09:23 +0000 | [diff] [blame] | 51 | |
Robert Lu | b03ca01 | 2018-01-18 19:06:39 +0800 | [diff] [blame] | 52 | if (!method_exists($trans, 'putBack')) { |
| 53 | $trans = new TBufferedTransport($trans); |
| 54 | } |
| 55 | parent::__construct($trans, $strictRead, $strictWrite); |
Roger Meier | 21c0a85 | 2012-09-05 19:47:14 +0000 | [diff] [blame] | 56 | } |
Robert Lu | b03ca01 | 2018-01-18 19:06:39 +0800 | [diff] [blame] | 57 | |
| 58 | public function isStrictRead() |
| 59 | { |
| 60 | return $this->strictRead_; |
| 61 | } |
| 62 | |
| 63 | public function isStrictWrite() |
| 64 | { |
| 65 | return $this->strictWrite_; |
| 66 | } |
Jens Geyer | 1998338 | 2014-02-22 17:34:29 +0100 | [diff] [blame] | 67 | } |