blob: ff799a6ab8d1b77b575abab1c2912b67e8c784fe [file] [log] [blame]
Roger Meier21c0a852012-09-05 19:47:14 +00001<?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
Roger Meier21c0a852012-09-05 19:47:14 +000025use Thrift\Transport\TBufferedTransport;
26
27/**
28 * Accelerated binary protocol: used in conjunction with the thrift_protocol
29 * extension for faster deserialization
30 */
Roger Thomas6fb59232014-11-04 10:09:23 +000031class TBinaryProtocolAccelerated extends TBinaryProtocol
32{
Robert Lub03ca012018-01-18 19:06:39 +080033 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 Thomas6fb59232014-11-04 10:09:23 +000037
Robert Lub03ca012018-01-18 19:06:39 +080038 // 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 Thomas6fb59232014-11-04 10:09:23 +000051
Robert Lub03ca012018-01-18 19:06:39 +080052 if (!method_exists($trans, 'putBack')) {
53 $trans = new TBufferedTransport($trans);
54 }
55 parent::__construct($trans, $strictRead, $strictWrite);
Roger Meier21c0a852012-09-05 19:47:14 +000056 }
Robert Lub03ca012018-01-18 19:06:39 +080057
58 public function isStrictRead()
59 {
60 return $this->strictRead_;
61 }
62
63 public function isStrictWrite()
64 {
65 return $this->strictWrite_;
66 }
Jens Geyer19983382014-02-22 17:34:29 +010067}