1<?hh // strict
2/*
3 * Copyright (c) Facebook, Inc. and its affiliates.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * @package thrift.transport
18 */
19
20/**
21 * TTransport subclasses that implement InstrumentedTTransport and use
22 * InstrumentedTTransportTrait have a simple set of counters available.
23 */
24trait InstrumentedTTransportTrait {
25  private int $bytesWritten = 0;
26  private int $bytesRead = 0;
27
28  public function getBytesWritten(): int {
29    return $this->bytesWritten;
30  }
31
32  public function getBytesRead(): int {
33    return $this->bytesRead;
34  }
35
36  public function resetBytesWritten(): void {
37    $this->bytesWritten = 0;
38  }
39
40  public function resetBytesRead(): void {
41    $this->bytesRead = 0;
42  }
43
44  protected function onWrite(int $bytes_written): void {
45    $this->bytesWritten += $bytes_written;
46  }
47
48  protected function onRead(int $bytes_read): void {
49    $this->bytesRead += $bytes_read;
50  }
51}
52