1 /* 2 * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 #ifndef NET_DCSCTP_PUBLIC_DCSCTP_MESSAGE_H_ 11 #define NET_DCSCTP_PUBLIC_DCSCTP_MESSAGE_H_ 12 13 #include <cstdint> 14 #include <utility> 15 #include <vector> 16 17 #include "api/array_view.h" 18 #include "net/dcsctp/public/types.h" 19 20 namespace dcsctp { 21 22 // An SCTP message is a group of bytes sent and received as a whole on a 23 // specified stream identifier (`stream_id`), and with a payload protocol 24 // identifier (`ppid`). 25 class DcSctpMessage { 26 public: DcSctpMessage(StreamID stream_id,PPID ppid,std::vector<uint8_t> payload)27 DcSctpMessage(StreamID stream_id, PPID ppid, std::vector<uint8_t> payload) 28 : stream_id_(stream_id), ppid_(ppid), payload_(std::move(payload)) {} 29 30 DcSctpMessage(DcSctpMessage&& other) = default; 31 DcSctpMessage& operator=(DcSctpMessage&& other) = default; 32 DcSctpMessage(const DcSctpMessage&) = delete; 33 DcSctpMessage& operator=(const DcSctpMessage&) = delete; 34 35 // The stream identifier to which the message is sent. stream_id()36 StreamID stream_id() const { return stream_id_; } 37 38 // The payload protocol identifier (ppid) associated with the message. ppid()39 PPID ppid() const { return ppid_; } 40 41 // The payload of the message. payload()42 rtc::ArrayView<const uint8_t> payload() const { return payload_; } 43 44 // When destructing the message, extracts the payload. ReleasePayload()45 std::vector<uint8_t> ReleasePayload() && { return std::move(payload_); } 46 47 private: 48 StreamID stream_id_; 49 PPID ppid_; 50 std::vector<uint8_t> payload_; 51 }; 52 } // namespace dcsctp 53 54 #endif // NET_DCSCTP_PUBLIC_DCSCTP_MESSAGE_H_ 55