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_CHUNK_H_ 11 #define NET_DCSCTP_PACKET_CHUNK_CHUNK_H_ 12 13 #include <stddef.h> 14 #include <sys/types.h> 15 16 #include <cstdint> 17 #include <iterator> 18 #include <memory> 19 #include <string> 20 #include <utility> 21 #include <vector> 22 23 #include "absl/algorithm/container.h" 24 #include "absl/strings/string_view.h" 25 #include "absl/types/optional.h" 26 #include "api/array_view.h" 27 #include "net/dcsctp/packet/data.h" 28 #include "net/dcsctp/packet/error_cause/error_cause.h" 29 #include "net/dcsctp/packet/parameter/parameter.h" 30 #include "net/dcsctp/packet/tlv_trait.h" 31 32 namespace dcsctp { 33 34 // Base class for all SCTP chunks 35 class Chunk { 36 public: Chunk()37 Chunk() {} 38 virtual ~Chunk() = default; 39 40 // Chunks can contain data payloads that shouldn't be copied unnecessarily. 41 Chunk(Chunk&& other) = default; 42 Chunk& operator=(Chunk&& other) = default; 43 Chunk(const Chunk&) = delete; 44 Chunk& operator=(const Chunk&) = delete; 45 46 // Serializes the chunk to `out`, growing it as necessary. 47 virtual void SerializeTo(std::vector<uint8_t>& out) const = 0; 48 49 // Returns a human readable description of this chunk and its parameters. 50 virtual std::string ToString() const = 0; 51 }; 52 53 // Introspects the chunk in `data` and returns a human readable textual 54 // representation of it, to be used in debugging. 55 std::string DebugConvertChunkToString(rtc::ArrayView<const uint8_t> data); 56 57 struct ChunkConfig { 58 static constexpr int kTypeSizeInBytes = 1; 59 }; 60 61 } // namespace dcsctp 62 63 #endif // NET_DCSCTP_PACKET_CHUNK_CHUNK_H_ 64