Skip to content

[C#] Avoid ToString() affect the message internal state #993

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Aug 1, 2024

Conversation

amibar
Copy link
Contributor

@amibar amibar commented Apr 25, 2024

Hi,

This PR intends to fix Issue 992.

The current generate ToString() implementation calls to this.BuildString() which change this state.

public override string ToString()
{
    var sb = new StringBuilder(100);
    this.BuildString(sb);
    return sb.ToString();
}

To avoid the affect ton this, I changed the generated ToString() to create a new instance of the message, wrap it and then use it with BuildString(). This way this is not affected.

public override string ToString()
{
    var sb = new StringBuilder(100);
    var m = new GroupAndVarLength();
    m.WrapForDecode(_buffer, _offset, _actingBlockLength, _actingVersion);
    m.BuildString(sb);
    return sb.ToString();
}

The assumption is that ToString() is only called for logging and debugging purposes, so the extra object created doesn't affect performance.

Ami

@amibar
Copy link
Contributor Author

amibar commented Aug 1, 2024

Hi,

Can someone merge this pull request anytime ?

Ami

@ZachBray ZachBray merged commit 4ddf522 into aeron-io:master Aug 1, 2024
@amibar
Copy link
Contributor Author

amibar commented Aug 1, 2024

Thanks

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[C#] ToString() affects the message state
2 participants