Skip to content
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

Move operation in the reflection API in C++ #19045

Open
christopher-kwan-ai opened this issue Oct 30, 2024 · 2 comments
Open

Move operation in the reflection API in C++ #19045

christopher-kwan-ai opened this issue Oct 30, 2024 · 2 comments

Comments

@christopher-kwan-ai
Copy link

What language does this apply to?
CPP

If it's a proto syntax change, is it for proto2 or proto3?
Proto3

Describe the problem you are trying to solve.

Trying to use the reflection API in C++. My reflected proto contains a bytes field but I am not able to find a way to move the bytes out of the reflected message. It looks like the methods available only provide references.

Describe the solution you'd like
Would like to be able to move bytes out of the message, similar to how I can make a MutableMessage call or a ReleaseMessage call on nested messages.

Describe alternatives you've considered
NA

Additional context
I'm moving this bytes field into a separate proto message and would like to avoid the copy cost.

@christopher-kwan-ai christopher-kwan-ai added the untriaged auto added to all issues by default when created. label Oct 30, 2024
@sbenzaquen
Copy link
Contributor

There currently are no "move" operations in the reflection API.
I can offer you two options:

  • Reflection::SwapField to swap the field into the destination message. This only works if it is the same field on source and destination, though.
  • Use absl::Cord as the underlying type. This type has copy-on-write semantics so you can "get" from the source and "set" on the destination without a deep copy. See https://protobuf.dev/reference/cpp/cpp-generated/#cord

@sbenzaquen sbenzaquen added wait for user action and removed untriaged auto added to all issues by default when created. labels Oct 30, 2024
@christopher-kwan-ai
Copy link
Author

Thanks for the response. It sounds like both source and destination will need to support Cord in this case if I would like to enjoy that optimization. Any clues if the move operations will be something that is on the roadmap? Would love to see this as an available feature

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

No branches or pull requests

2 participants