C++ deserialization#31
Conversation
6225cb2 to
a417702
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new deserialization component (BufferReaderImpl) under the existing L5 module, including its interface, implementation, tests, and build updates.
- Introduces
IBufferReaderinterface and implementsBufferReaderImplwith methods for reading various integer sizes and UTF strings. - Adds unit tests for
readUInt8/16/32/64andreadUTFString. - Updates CMakeLists to include the new implementation and test files.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| native/V2StyxLib/modules/l5/include/serialization/IBufferReader.h | New interface declaration for buffer reading |
| native/V2StyxLib/modules/l5/include/serialization/BufferReaderImpl.h | Declaration of BufferReaderImpl subclass |
| native/V2StyxLib/modules/l5/src/BufferReaderImpl.cpp | Implementation of deserialization methods |
| native/V2StyxLib/modules/l5/test/test_BufferReaderImpl.cpp | Unit tests for the new reader methods |
| native/V2StyxLib/modules/l5/CMakeLists.txt | Build updates to include new source and test files |
Comments suppressed due to low confidence (1)
native/V2StyxLib/modules/l5/test/test_BufferReaderImpl.cpp:37
- Consider adding tests for the
read(uint8_t*, Styx::Size)method and buffer overflow/error cases (e.g., out-of-range reads) to improve overall coverage.
}
| if (buf == nullptr) { | ||
| throw std::invalid_argument("Buffer cannot be null"); | ||
| } | ||
| position = 0; |
There was a problem hiding this comment.
[nitpick] Duplicate initialization of position (it’s already set in the initializer list); consider removing this assignment in the constructor body.
| position = 0; |
| for (Styx::Size i = 0; i < count; ++i) { | ||
| data[i] = buffer[position++]; | ||
| } |
There was a problem hiding this comment.
For bulk reads, prefer std::memcpy(data, buffer + position, count); position += count; to avoid the per-byte loop and improve performance.
| for (Styx::Size i = 0; i < count; ++i) { | |
| data[i] = buffer[position++]; | |
| } | |
| std::memcpy(data, buffer + position, count); | |
| position += count; |
| Styx::Size limit; | ||
| public: | ||
| BufferReaderImpl(const StyxBuffer &buf, Styx::Size size); | ||
| virtual ~BufferReaderImpl(); |
There was a problem hiding this comment.
[nitpick] The destructor is empty; you can simplify by defaulting it (~BufferReaderImpl() override = default;) to reduce boilerplate.
| virtual ~BufferReaderImpl(); | |
| ~BufferReaderImpl() override = default; |
No description provided.