Skip to content

Commit d4fd579

Browse files
committed
cosmetic
1 parent 779e645 commit d4fd579

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

worker/include/RTC/SCTP/Packet.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace RTC
6666
* @remarks
6767
* - `length` must be the exact length of the Packet.
6868
*/
69-
static Packet* Parse(const uint8_t* buffer, size_t length);
69+
static Packet* Parse(const uint8_t* buffer, size_t bufferLength);
7070

7171
static Packet* Factory(uint8_t* buffer, size_t bufferLength);
7272

worker/src/RTC/SCTP/Packet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// );
2828
// }
2929

30-
// Packet* Packet::Parse(const uint8_t* buffer, size_t length)
30+
// Packet* Packet::Parse(const uint8_t* buffer, size_t bufferLength)
3131
// {
3232
// MS_TRACE();
3333

worker/test/include/RTC/TestSerializable/FooPacket.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class FooPacket : public Serializable
7474
* @remarks
7575
* - `length` must be the exact length of the Packet.
7676
*/
77-
static FooPacket* Parse(const uint8_t* buffer, size_t length);
77+
static FooPacket* Parse(const uint8_t* buffer, size_t bufferLength);
7878

7979
static FooPacket* Factory(uint8_t* buffer, size_t bufferLength, uint8_t type);
8080

worker/test/src/RTC/TestSerializable/FooPacket.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#define MS_CLASS "RTC::TestSerializable:FooPacket"
2-
// #define MS_LOG_DEV_LEVEL 3
2+
#define MS_LOG_DEV_LEVEL 3
33

44
#include "RTC/TestSerializable/FooPacket.hpp"
55
#include "Logger.hpp"
@@ -42,21 +42,18 @@ bool FooPacket::IsFooPacket(const uint8_t* buffer, size_t bufferLength)
4242
return true;
4343
}
4444

45-
FooPacket* FooPacket::Parse(const uint8_t* buffer, size_t length)
45+
FooPacket* FooPacket::Parse(const uint8_t* buffer, size_t bufferLength)
4646
{
4747
MS_TRACE();
4848

49-
if (!FooPacket::IsFooPacket(buffer, length))
49+
if (!FooPacket::IsFooPacket(buffer, bufferLength))
5050
{
5151
MS_WARN_DEV("not a FooPacket");
5252

5353
return nullptr;
5454
}
5555

56-
// NOTE: Here we are passing `length` as `bufferLength`. However we know
57-
// that, due to FooPacket nature, a FooPacket Packet must occupy the whole
58-
// given buffer.
59-
auto* packet = new FooPacket(buffer, length);
56+
auto* packet = new FooPacket(buffer, bufferLength);
6057

6158
// Pointer that starts at the beginning of the buffer and it's incremented
6259
// to point to different parts of the Packet.
@@ -67,22 +64,21 @@ FooPacket* FooPacket::Parse(const uint8_t* buffer, size_t length)
6764

6865
while (ptr < buffer + packet->GetLengthField())
6966
{
70-
// Here we must anticipate the id of each item to use its appropriate.
71-
if (ptr + FooItem::ItemHeaderLength > packet->GetPaddingPointer())
67+
// The remaining length in the buffer (excluding padding in the packet)
68+
// is the potential buffer length of the item.
69+
size_t itemBufferLength = packet->GetPaddingPointer() - ptr;
70+
71+
FooItem::ItemId itemId;
72+
uint8_t valueLength;
73+
74+
if (!FooItem::IsFooItem(ptr, itemBufferLength, itemId, valueLength))
7275
{
73-
MS_WARN_DEV("no space for item header");
76+
MS_WARN_DEV("not a FooItem");
7477

7578
delete packet;
7679
return nullptr;
7780
}
7881

79-
const auto* itemHeader = reinterpret_cast<const FooItem::ItemHeader*>(ptr);
80-
auto itemId = itemHeader->id;
81-
82-
// The remaining length in the buffer (excluding padding in the packet)
83-
// is the potential buffer length of the item.
84-
size_t itemBufferLength = packet->GetPaddingPointer() - ptr;
85-
8682
FooItem* item{ nullptr };
8783

8884
MS_DEBUG_DEV("parsing FooItem [ptr:%zu, id:%" PRIu8 "]", ptr - buffer, itemId);
@@ -154,9 +150,9 @@ FooPacket* FooPacket::Parse(const uint8_t* buffer, size_t length)
154150

155151
const size_t computedLength = Utils::Byte::PadTo4Bytes(static_cast<size_t>(ptr - buffer));
156152

157-
// Ensure computed length (padded to 4 bytes) matches the total given
153+
// Ensure computed length (padded to 4 bytes) matches the total given buffer
158154
// length.
159-
if (computedLength != length)
155+
if (computedLength != bufferLength)
160156
{
161157
MS_WARN_DEV("computed padded length != buffer length");
162158

0 commit comments

Comments
 (0)