Skip to content

[C#] Adding Clear mechanism to IMessage #21472

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ifshuaishuai
Copy link

Motivation

In C# game development or real-time bidding, object pooling is a common way to optimize. However, the C# runtime of Protobuf does not support Clear message. See issue: #18782.

This pull request add Clear method to IMessage.cs, makes Protobuf C# message can be reused.

What's added or changed

  • Protoc: csharp codegen add Clear() method, inspired of java clear() implementation.
  • WellKnown protos: Regenerated by Protoc tools above.
  • IMessage: interface add Clear() method, few old proto generated file or C# file was correct by hand.
  • Tests: base unit tests are included.

If this pull request has any breaking changes or improvement, please let me know. And I will try my best to improve it.

Thanks for your time.

@ifshuaishuai ifshuaishuai requested a review from a team as a code owner April 26, 2025 03:44
@ifshuaishuai ifshuaishuai requested review from jskeet and removed request for a team April 26, 2025 03:44
@jskeet jskeet removed their request for review April 26, 2025 05:44
@jskeet
Copy link
Contributor

jskeet commented Apr 26, 2025

Removed myself as a reviewer as I don't have time to consider this thoroughly, but if I were reviewing it I would reject it in its current state as adding a method to an interface is a breaking change.

@acozzette acozzette added the c# label Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants