Skip to content

[Core] Add ToDecString/FromDecString serialization helpers - #2185

Open
sebaszm wants to merge 4 commits into
masterfrom
development/todecstring
Open

[Core] Add ToDecString/FromDecString serialization helpers#2185
sebaszm wants to merge 4 commits into
masterfrom
development/todecstring

Conversation

@sebaszm

@sebaszm sebaszm commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

to facilitate JsonGenerator @encode:ip

Copilot AI review requested due to automatic review settings July 24, 2026 13:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / FromDecString overloads for uint8_t[] and std::vector<uint8_t>.
  • Adjusted FromHexString’s raw-buffer parameter spelling to uint8_t object[] (equivalent to uint8_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.

Comment thread Source/core/Serialization.cpp Outdated
Comment thread Source/core/Serialization.cpp Outdated
Comment thread Source/core/Serialization.cpp Outdated
Comment thread Source/core/Serialization.cpp Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 24, 2026 13:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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');

Comment thread Source/core/Serialization.cpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 24, 2026 13:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • ToDecString only enforces delimiter != '\0' via ASSERT(). In non-debug builds a \0 delimiter will be embedded into result, 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

  • FromDecString relies on ASSERT(delimiter != '\0') only; in release builds, passing \0 makes 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;

Comment thread Source/core/Serialization.h
@sebaszm
sebaszm requested a review from VeithMetro July 24, 2026 14:11
void ToDecString(const uint8_t object[], const uint32_t length, string& result, const TCHAR delimiter)
{
ASSERT(object != nullptr);
ASSERT(delimiter != '\0');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make it idiot-proof and add an ASSERT if someone passes a decimal digit as an delimiter?

haveValue = false;
}
else {
failure = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In FromHexString, we still return the number of values that fit even when maxLength is reached, shouldn't it be like this here too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants