TBinaryProtocolAccelerated.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\Transport\TBufferedTransport;
  24. /**
  25. * Accelerated binary protocol: used in conjunction with the thrift_protocol
  26. * extension for faster deserialization
  27. */
  28. class TBinaryProtocolAccelerated extends TBinaryProtocol
  29. {
  30. public function __construct($trans, $strictRead=false, $strictWrite=true)
  31. {
  32. // If the transport doesn't implement putBack, wrap it in a
  33. // TBufferedTransport (which does)
  34. // NOTE (t.heintz): This is very evil to do, because the TBufferedTransport may swallow bytes, which
  35. // are then never written to the underlying transport. This happens precisely when a number of bytes
  36. // less than the max buffer size (512 by default) is written to the transport and then flush() is NOT
  37. // called. In that case the data stays in the writeBuffer of the transport, from where it can never be
  38. // accessed again (for example through read()).
  39. //
  40. // Since the caller of this method does not know about the wrapping transport, this creates bugs which
  41. // are very difficult to find. Hence the wrapping of a transport in a buffer should be left to the
  42. // calling code. An interface could used to mandate the presence of the putBack() method in the transport.
  43. //
  44. // I am leaving this code in nonetheless, because there may be applications depending on this behavior.
  45. //
  46. // @see THRIFT-1579
  47. if (!method_exists($trans, 'putBack')) {
  48. $trans = new TBufferedTransport($trans);
  49. }
  50. parent::__construct($trans, $strictRead, $strictWrite);
  51. }
  52. public function isStrictRead()
  53. {
  54. return $this->strictRead_;
  55. }
  56. public function isStrictWrite()
  57. {
  58. return $this->strictWrite_;
  59. }
  60. }