/Users/deen/code/yugabyte-db/src/yb/rpc/call_data.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #ifndef YB_RPC_CALL_DATA_H |
15 | | #define YB_RPC_CALL_DATA_H |
16 | | |
17 | | #include "yb/util/ref_cnt_buffer.h" |
18 | | #include "yb/util/strongly_typed_bool.h" |
19 | | |
20 | | namespace yb { |
21 | | namespace rpc { |
22 | | |
23 | | struct CallData { |
24 | | public: |
25 | 75.8M | CallData() : buffer_(EmptyBuffer()) {} |
26 | | |
27 | 37.7M | explicit CallData(size_t size) : buffer_(size) {} |
28 | | class ShouldRejectTag {}; |
29 | | |
30 | 0 | CallData(size_t size, ShouldRejectTag) {} |
31 | | |
32 | | CallData(const CallData&) = delete; |
33 | | void operator=(const CallData&) = delete; |
34 | | |
35 | | CallData(CallData&& rhs) = default; |
36 | 54.2M | CallData& operator=(CallData&& rhs) = default; |
37 | | |
38 | 35.2M | bool empty() const { |
39 | 35.2M | return buffer_.empty(); |
40 | 35.2M | } |
41 | | |
42 | 87.6M | char* data() const { |
43 | 87.6M | return buffer_.data(); |
44 | 87.6M | } |
45 | | |
46 | 36.7M | bool should_reject() const { return !buffer_; } |
47 | | |
48 | 1.54M | void Reset() { |
49 | 1.54M | buffer_.Reset(); |
50 | 1.54M | } |
51 | | |
52 | 156M | size_t size() const { |
53 | 156M | return buffer_.size(); |
54 | 156M | } |
55 | | |
56 | 2.06M | const RefCntBuffer& buffer() const { |
57 | 2.06M | return buffer_; |
58 | 2.06M | } |
59 | | |
60 | 19.5M | size_t DynamicMemoryUsage() const { return buffer_.DynamicMemoryUsage(); } |
61 | | |
62 | | private: |
63 | 65.9M | static RefCntBuffer EmptyBuffer() { |
64 | 65.9M | static RefCntBuffer result(0); |
65 | 65.9M | return result; |
66 | 65.9M | } |
67 | | |
68 | | RefCntBuffer buffer_; |
69 | | }; |
70 | | |
71 | | } // namespace rpc |
72 | | } // namespace yb |
73 | | |
74 | | #endif // YB_RPC_CALL_DATA_H |