Skip to content

Commit

Permalink
Core: Add ->as<> helper to CBasicPacket
Browse files Browse the repository at this point in the history
  • Loading branch information
zach2good committed Jan 14, 2025
1 parent 8e1d37e commit 0c5c0fc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/map/packets/basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,21 @@ class CBasicPacket
ref<uint16>(2) = new_sequence;
}

/* Indexer for the data buffer */
// Indexer for the buffer's data
template <typename T>
T& ref(std::size_t index)
{
return ::ref<T>(buffer_.data(), index);
}

// Reinterpret and use the underlying buffer as a different type
template <typename T>
auto as() -> std::remove_pointer_t<T>*
{
using Type = std::remove_pointer_t<T>;
return reinterpret_cast<Type*>(buffer_.data());
}

operator uint8*()
{
return buffer_.data();
Expand Down

0 comments on commit 0c5c0fc

Please sign in to comment.