#define MS_CLASS "RTC::SCTP::AbortAssociationChunk"
#include "RTC/SCTP/packet/chunks/AbortAssociationChunk.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
namespace RTC
{
namespace SCTP
{
AbortAssociationChunk* AbortAssociationChunk::Parse(const uint8_t* buffer, size_t bufferLength)
{
MS_TRACE();
Chunk::ChunkType chunkType;
uint16_t chunkLength;
uint8_t padding;
if (!Chunk::IsChunk(buffer, bufferLength, chunkType, chunkLength, padding))
{
return nullptr;
}
if (chunkType != Chunk::ChunkType::ABORT)
{
MS_WARN_DEV("invalid chunk type");
return nullptr;
}
return AbortAssociationChunk::ParseStrict(buffer, bufferLength, chunkLength, padding);
}
AbortAssociationChunk* AbortAssociationChunk::Factory(uint8_t* buffer, size_t bufferLength)
{
MS_TRACE();
if (bufferLength < Chunk::ChunkHeaderLength)
{
MS_THROW_TYPE_ERROR("buffer too small");
}
auto* chunk = new AbortAssociationChunk(buffer, bufferLength);
chunk->InitializeHeader(Chunk::ChunkType::ABORT, 0, Chunk::ChunkHeaderLength);
return chunk;
}
AbortAssociationChunk* AbortAssociationChunk::ParseStrict(
const uint8_t* buffer, size_t bufferLength, uint16_t chunkLength, uint8_t padding)
{
MS_TRACE();
auto* chunk = new AbortAssociationChunk(const_cast<uint8_t*>(buffer), bufferLength);
if (!chunk->ParseErrorCauses())
{
MS_WARN_DEV("failed to parse error causes");
delete chunk;
return nullptr;
}
chunk->SetLength(chunkLength + padding);
return chunk;
}
AbortAssociationChunk::AbortAssociationChunk(uint8_t* buffer, size_t bufferLength)
: Chunk(buffer, bufferLength)
{
MS_TRACE();
SetLength(Chunk::ChunkHeaderLength);
}
AbortAssociationChunk::~AbortAssociationChunk()
{
MS_TRACE();
}
void AbortAssociationChunk::Dump(int indentation) const
{
MS_TRACE();
MS_DUMP_CLEAN(indentation, "<SCTP::AbortAssociationChunk>");
DumpCommon(indentation);
MS_DUMP_CLEAN(indentation, " flag T: %" PRIu8, GetT());
DumpErrorCauses(indentation);
MS_DUMP_CLEAN(indentation, "</SCTP::AbortAssociationChunk>");
}
AbortAssociationChunk* AbortAssociationChunk::Clone(uint8_t* buffer, size_t bufferLength) const
{
MS_TRACE();
auto* clonedChunk = new AbortAssociationChunk(buffer, bufferLength);
CloneInto(clonedChunk);
SoftCloneInto(clonedChunk);
return clonedChunk;
}
void AbortAssociationChunk::SetT(bool flag)
{
MS_TRACE();
SetBit0(flag);
}
AbortAssociationChunk* AbortAssociationChunk::SoftClone(const uint8_t* buffer) const
{
MS_TRACE();
auto* softClonedChunk = new AbortAssociationChunk(const_cast<uint8_t*>(buffer), GetLength());
SoftCloneInto(softClonedChunk);
return softClonedChunk;
}
} }