1 // Copyright 2024 gRPC authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://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, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef GRPC_SRC_CORE_LIB_TRANSPORT_MESSAGE_H 16 #define GRPC_SRC_CORE_LIB_TRANSPORT_MESSAGE_H 17 18 #include <grpc/support/port_platform.h> 19 20 #include "src/core/lib/resource_quota/arena.h" 21 #include "src/core/lib/slice/slice_buffer.h" 22 23 /// Internal bit flag for grpc_begin_message's \a flags signaling the use of 24 /// compression for the message. (Does not apply for stream compression.) 25 #define GRPC_WRITE_INTERNAL_COMPRESS (0x80000000u) 26 /// Internal bit flag for determining whether the message was compressed and had 27 /// to be decompressed by the message_decompress filter. (Does not apply for 28 /// stream compression.) 29 #define GRPC_WRITE_INTERNAL_TEST_ONLY_WAS_COMPRESSED (0x40000000u) 30 /// Mask of all valid internal flags. 31 #define GRPC_WRITE_INTERNAL_USED_MASK \ 32 (GRPC_WRITE_INTERNAL_COMPRESS | GRPC_WRITE_INTERNAL_TEST_ONLY_WAS_COMPRESSED) 33 34 namespace grpc_core { 35 36 class Message { 37 public: 38 Message() = default; 39 ~Message() = default; Message(SliceBuffer payload,uint32_t flags)40 Message(SliceBuffer payload, uint32_t flags) 41 : payload_(std::move(payload)), flags_(flags) {} 42 Message(const Message&) = delete; 43 Message& operator=(const Message&) = delete; 44 flags()45 uint32_t flags() const { return flags_; } mutable_flags()46 uint32_t& mutable_flags() { return flags_; } payload()47 SliceBuffer* payload() { return &payload_; } payload()48 const SliceBuffer* payload() const { return &payload_; } 49 50 std::string DebugString() const; 51 52 private: 53 SliceBuffer payload_; 54 uint32_t flags_ = 0; 55 }; 56 57 using MessageHandle = Arena::PoolPtr<Message>; 58 59 } // namespace grpc_core 60 61 #endif // GRPC_SRC_CORE_LIB_TRANSPORT_MESSAGE_H 62