[Core] Add ToDecString/FromDecString serialization helpers - #2185
[Core] Add ToDecString/FromDecString serialization helpers#2185sebaszm wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds decimal-list (de)serialization helpers to Thunder core so callers can convert byte buffers to/from a delimited decimal string representation (e.g., 192.168.0.1-style formats), alongside the existing hex/base64 helpers.
Changes:
- Added
ToDecString/FromDecStringoverloads foruint8_t[]andstd::vector<uint8_t>. - Adjusted
FromHexString’s raw-buffer parameter spelling touint8_t object[](equivalent touint8_t*). - Implemented decimal parsing/formatting logic in
Serialization.cpp.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
Source/core/Serialization.h |
Declares new ToDecString/FromDecString APIs and tweaks FromHexString raw-buffer parameter form. |
Source/core/Serialization.cpp |
Implements decimal formatting/parsing routines for byte arrays and vectors. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
Source/core/Serialization.cpp:227
- New ToDecString/FromDecString helpers are added, but there are existing unit tests for the hex helpers (e.g.
Tests/unit/core/test_hex2strserialization.cpp). Please add analogous unit tests for decimal serialization/deserialization (including delimiter handling, maxLength truncation, and invalid inputs), otherwise regressions in@encode:ip-style usage may go unnoticed.
void ToDecString(const uint8_t object[], const uint32_t length, string& result, const TCHAR delimiter)
{
ASSERT(object != nullptr);
ASSERT(delimiter != '\0');
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
Source/core/Serialization.cpp:227
ToDecStringonly enforcesdelimiter != '\0'viaASSERT(). In non-debug builds a\0delimiter will be embedded intoresult, which is very likely unintended (and can lead to truncated C-string usage). Consider adding a runtime guard so release builds fail safely.
void ToDecString(const uint8_t object[], const uint32_t length, string& result, const TCHAR delimiter)
{
ASSERT(object != nullptr);
ASSERT(delimiter != '\0');
Source/core/Serialization.cpp:274
FromDecStringrelies onASSERT(delimiter != '\0')only; in release builds, passing\0makes the parsing rules ambiguous and can produce surprising results. Add a runtime guard to return 0 on invalid delimiter values.
uint32_t FromDecString(const string& decString, uint8_t object[], uint32_t maxLength, const TCHAR delimiter)
{
ASSERT((object != nullptr) && (maxLength > 0));
ASSERT(delimiter != '\0');
uint32_t count = 0;
| void ToDecString(const uint8_t object[], const uint32_t length, string& result, const TCHAR delimiter) | ||
| { | ||
| ASSERT(object != nullptr); | ||
| ASSERT(delimiter != '\0'); |
There was a problem hiding this comment.
Should we make it idiot-proof and add an ASSERT if someone passes a decimal digit as an delimiter?
| haveValue = false; | ||
| } | ||
| else { | ||
| failure = true; |
There was a problem hiding this comment.
In FromHexString, we still return the number of values that fit even when maxLength is reached, shouldn't it be like this here too?
to facilitate JsonGenerator @encode:ip