xref: /aosp_15_r20/external/webrtc/net/dcsctp/packet/chunk/idata_chunk.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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_PACKET_CHUNK_IDATA_CHUNK_H_
11 #define NET_DCSCTP_PACKET_CHUNK_IDATA_CHUNK_H_
12 #include <stddef.h>
13 #include <stdint.h>
14 
15 #include <cstdint>
16 #include <string>
17 #include <utility>
18 #include <vector>
19 
20 #include "absl/strings/string_view.h"
21 #include "api/array_view.h"
22 #include "net/dcsctp/packet/chunk/chunk.h"
23 #include "net/dcsctp/packet/chunk/data_common.h"
24 #include "net/dcsctp/packet/data.h"
25 #include "net/dcsctp/packet/tlv_trait.h"
26 
27 namespace dcsctp {
28 
29 // https://tools.ietf.org/html/rfc8260#section-2.1
30 struct IDataChunkConfig : ChunkConfig {
31   static constexpr int kType = 64;
32   static constexpr size_t kHeaderSize = 20;
33   static constexpr size_t kVariableLengthAlignment = 1;
34 };
35 
36 class IDataChunk : public AnyDataChunk, public TLVTrait<IDataChunkConfig> {
37  public:
38   static constexpr int kType = IDataChunkConfig::kType;
39 
40   // Exposed to allow the retransmission queue to make room for the correct
41   // header size.
42   static constexpr size_t kHeaderSize = IDataChunkConfig::kHeaderSize;
IDataChunk(TSN tsn,StreamID stream_id,MID message_id,PPID ppid,FSN fsn,std::vector<uint8_t> payload,const Options & options)43   IDataChunk(TSN tsn,
44              StreamID stream_id,
45              MID message_id,
46              PPID ppid,
47              FSN fsn,
48              std::vector<uint8_t> payload,
49              const Options& options)
50       : AnyDataChunk(tsn,
51                      stream_id,
52                      SSN(0),
53                      message_id,
54                      fsn,
55                      ppid,
56                      std::move(payload),
57                      options) {}
58 
IDataChunk(TSN tsn,Data && data,bool immediate_ack)59   explicit IDataChunk(TSN tsn, Data&& data, bool immediate_ack)
60       : AnyDataChunk(tsn, std::move(data), immediate_ack) {}
61 
62   static absl::optional<IDataChunk> Parse(rtc::ArrayView<const uint8_t> data);
63 
64   void SerializeTo(std::vector<uint8_t>& out) const override;
65   std::string ToString() const override;
66 };
67 
68 }  // namespace dcsctp
69 
70 #endif  // NET_DCSCTP_PACKET_CHUNK_IDATA_CHUNK_H_
71