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

Protobuf dynamic typing in C# #11092

Closed
wants to merge 0 commits into from
Closed

Conversation

himkak
Copy link

@himkak himkak commented Nov 30, 2022

  • Added support for Dynamic typing by adding DynamicMessage for C#. The implementation closely follows the implementation done in java.
  • Added dotnet workflow for build and test C# code

@jskeet jskeet self-requested a review November 30, 2022 13:12
@jskeet
Copy link
Contributor

jskeet commented Nov 30, 2022

I'll have a look at this when I get some time, but it may not be for a while I'm afraid.

@himkak
Copy link
Author

himkak commented Nov 30, 2022

Sure, thanks.
It would be great if you could review it soon.
Ref issue : #658

@jskeet
Copy link
Contributor

jskeet commented Nov 30, 2022

It would be great if you could review it soon.

I strongly suspect we won't be in a position to merge until some time in 2023. Protobuf isn't my main role, so I'll only be able to put time into reviewing periodically. Do you have an urgent need for this for some reason?

@himkak
Copy link
Author

himkak commented Dec 1, 2022

I strongly suspect we won't be in a position to merge until some time in 2023. Protobuf isn't my main role, so I'll only be able to put time into reviewing periodically. Do you have an urgent need for this for some reason?

Yes, I am using these changes in my project, and looking to use the released version of the library.
Might be, if you can also pull someone who looks into Protobuf, to review these changes.
I would suggest to let's start reviewing the changes and make the changes merge ready.

@jskeet
Copy link
Contributor

jskeet commented Dec 1, 2022

Might be, if you can also pull someone who looks into Protobuf, to review these changes.

No, we really don't have enough C#-suitable resources - and close to the end of the year, lots of people are taking vacation time etc.
I'll try to have a quick look ahead of time to point out any large areas that need more work.

Copy link
Contributor

@jskeet jskeet left a comment

Choose a reason for hiding this comment

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

Overall, this isn't going in a direction I'd want to merge. I'd expect DynamicMessage to support:

  • Being handled like any other IMessage
  • JSON parsing and formatting
  • Reflection access via message.Descriptor.FindField(...).Accessor.GetValue(message) etc
  • Unknown fields

This all requires quite a bit of work, which is why it hasn't been done yet.

Given that this PR doesn't need to modify any existing code, I suggest that if it satisfies your needs, you keep it within your own codebase for now, and then migrate to whatever full support we end up with eventually.

@@ -0,0 +1,26 @@
# This workflow will build a .NET project
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't add a workflow as part of an entirely separate feature.
We already have testing via Kokoro.

using System;
using System.Collections;

namespace Google.Protobuf.Reflection.Dynamic
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we'll be able to use just Google.Protobuf.Reflection for this. I don't think a new sub-namespace is required.


/// <summary>
/// Default implementation of Overridden method.
/// This specific implementation is never used, mergeFrom is used from the builder class.
Copy link
Contributor

Choose a reason for hiding this comment

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

This prohibits it from being used in code that just uses IMessage.

/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static Builder NewBuilder(MessageDescriptor type)
Copy link
Contributor

Choose a reason for hiding this comment

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

The Java origins of this PR are really showing here. We don't use builders in the .NET implementation; instead, all messages are mutable. I'd expect DynamicMessage to follow that pattern.

@himkak
Copy link
Author

himkak commented Dec 1, 2022

Thanks a lot for quickly reviewing this PR.
Got your point. Let me try to make the changes in this PR, according to your suggestions.
If it will not look doable, will proceed as you suggested.

@jskeet
Copy link
Contributor

jskeet commented Dec 1, 2022

You're welcome to try - but having looked at this a few times (and having worked in this codebase for 14 years) it's always felt like a daunting prospect to me, with changes required across the reflection code as well as creating the core DynamicMessage type itself.

@himkak
Copy link
Author

himkak commented Dec 22, 2022

I have created a new PR in my forked repo itself. It tries to follow the same pattern as other IMessage implementations do.
Have a quick look and if it looks close to what is expected, will raise a PR against the main repo branch.
himkak protobuf PR 2

@jskeet
Copy link
Contributor

jskeet commented Dec 22, 2022

I'm on vacation now until January. I'll have a look next time I'm working.

@himkak
Copy link
Author

himkak commented Dec 22, 2022

Sure, Merry Christmas and Happy New Year in advance. Enjoy your vacation.

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.

None yet

3 participants