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 #include "net/dcsctp/packet/chunk/shutdown_chunk.h" 11 12 #include <stdint.h> 13 14 #include <type_traits> 15 #include <vector> 16 17 #include "absl/types/optional.h" 18 #include "api/array_view.h" 19 #include "net/dcsctp/packet/bounded_byte_reader.h" 20 #include "net/dcsctp/packet/bounded_byte_writer.h" 21 #include "net/dcsctp/packet/tlv_trait.h" 22 23 namespace dcsctp { 24 25 // https://tools.ietf.org/html/rfc4960#section-3.3.8 26 27 // 0 1 2 3 28 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 29 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 30 // | Type = 7 | Chunk Flags | Length = 8 | 31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 32 // | Cumulative TSN Ack | 33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 34 constexpr int ShutdownChunk::kType; 35 Parse(rtc::ArrayView<const uint8_t> data)36absl::optional<ShutdownChunk> ShutdownChunk::Parse( 37 rtc::ArrayView<const uint8_t> data) { 38 absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data); 39 if (!reader.has_value()) { 40 return absl::nullopt; 41 } 42 43 TSN cumulative_tsn_ack(reader->Load32<4>()); 44 return ShutdownChunk(cumulative_tsn_ack); 45 } 46 SerializeTo(std::vector<uint8_t> & out) const47void ShutdownChunk::SerializeTo(std::vector<uint8_t>& out) const { 48 BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out); 49 writer.Store32<4>(*cumulative_tsn_ack_); 50 } 51 ToString() const52std::string ShutdownChunk::ToString() const { 53 return "SHUTDOWN"; 54 } 55 } // namespace dcsctp 56