1 // Copyright 2021 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 #pragma once 15 16 #include "pw_rpc/internal/call.h" 17 18 namespace pw::rpc { 19 20 // The Writer class allows writing requests or responses to a streaming RPC. 21 // ClientWriter, ClientReaderWriter, ServerWriter, and ServerReaderWriter 22 // classes can be used as a generic Writer. 23 class Writer : private internal::Call { 24 public: 25 // Writers cannot be created directly. They may only be used as a reference to 26 // an existing call object. 27 Writer() = delete; 28 29 Writer(const Writer&) = delete; 30 Writer(Writer&&) = delete; 31 32 Writer& operator=(const Writer&) = delete; 33 Writer& operator=(Writer&&) = delete; 34 35 using internal::Call::active; 36 using internal::Call::channel_id; 37 38 using internal::Call::Write; 39 40 private: 41 friend class internal::Call; 42 }; 43 44 namespace internal { 45 46 constexpr Call::operator Writer&() { return static_cast<Writer&>(*this); } 47 48 constexpr Call::operator const Writer&() const { 49 return static_cast<const Writer&>(*this); 50 } 51 52 } // namespace internal 53 } // namespace pw::rpc 54