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

Update to latest protogen #628

Closed
wants to merge 7 commits into from
Closed

Update to latest protogen #628

wants to merge 7 commits into from

Conversation

xPaw
Copy link
Member

@xPaw xPaw commented Jan 18, 2019

I patched protogen with the following:

  • Skip generating Extensions
  • Always generate List<> instead of arrays types to match current behaviour
  • Force proto2 if syntax is not specified

The patch file is attached in the PR.

Things that need to be done:

@codecov-io
Copy link

codecov-io commented Jan 18, 2019

Codecov Report

Merging #628 into master will increase coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #628      +/-   ##
==========================================
+ Coverage   23.59%   23.65%   +0.05%     
==========================================
  Files          85       85              
  Lines        8709     8718       +9     
  Branches      719      719              
==========================================
+ Hits         2055     2062       +7     
- Misses       6523     6525       +2     
  Partials      131      131
Impacted Files Coverage Δ
SteamKit2/SteamKit2/Steam/CDNClient.cs 0% <0%> (ø) ⬆️
...mClient/Configuration/SteamConfigurationBuilder.cs 100% <0%> (ø) ⬆️
SteamKit2/SteamKit2/Util/HardwareUtils.cs 25.83% <0%> (+0.34%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ec01c92...2886f64. Read the comment docs.

@yaakov-h
Copy link
Member

I really don't like patching the binaries, and I don't think it will be maintainable going forwards.

Can we follow the original suggestion from the other issue and have our own generator frontend that's more tailored for our use?

@xPaw
Copy link
Member Author

xPaw commented Jan 22, 2019

The patch is a proof of concept, as it currently compiles steamkit but throws during serialisation.

@xPaw
Copy link
Member Author

xPaw commented Jan 23, 2019

Okay, so I figured out why it failed to serialize with new protogen. It generates the following attribute for some properties:

[global::System.ComponentModel.DefaultValue(18446744073709551615)]

And for whatever reason that makes protobuf-net fail to serialize it with Arithmetic operation resulted in an overflow.. I patched protogen so it no longer generates that and it appears to work now.

Old protogen didn't generate that, updating protobuf-net doesn't fix it, so I suspect it's a bug.

The following code throws, and removing ComponentModel.DefaultValue makes it work again.

        [global::ProtoBuf.ProtoMember(10, DataFormat = global::ProtoBuf.DataFormat.FixedSize)]
        [global::System.ComponentModel.DefaultValue(18446744073709551615)]
        public ulong jobid_source
        {
            get { return __pbn__jobid_source ?? 18446744073709551615; }
            set { __pbn__jobid_source = value; }
        }

@mgravell Would you have any idea what could be going on here?

@mgravell
Copy link

mgravell commented Jan 23, 2019 via email

@xPaw
Copy link
Member Author

xPaw commented Jan 23, 2019

Adding UL does not fix it, and I just checked, it passes the value into DefaultValue(float) overload, as there doesn't appear to be any unsigned overloads: https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.defaultvalueattribute.-ctor?view=netframework-4.7.2

EDIT: Doing DefaultValue(typeof(ulong), "18446744073709551615") doesn't throw, but I'm unsure if that's correct.

@mgravell
Copy link

mgravell commented Jan 23, 2019 via email

@xPaw
Copy link
Member Author

xPaw commented Feb 5, 2019

Turns out protogen already had the underlying support for writing services, the c# generator simply didn't implement them. So I implemented the interface generation, it skips any options though, but it should be good enough for SteamKit.

Technically speaking this is now fully compatible with SteamKit (I'm not sure if skipping DefaultValue will have any issues or not).

@mgravell
Copy link

mgravell commented Feb 5, 2019

@xPaw I'd be happy to look at a PR, if the service code would be more generally useful

@xPaw
Copy link
Member Author

xPaw commented Feb 5, 2019

Yeah I made a PR in the protobuf repo. protobuf-net/protobuf-net#492

@mgravell
Copy link

mgravell commented Feb 5, 2019

ah, k; I'll check that later; btw - if you don't want to keep having to upload binaries, all of the codegen code is available as a package ref to protobuf-net.Reflection - protogen is a trivial wrapper that just nudges the lib

@xPaw
Copy link
Member Author

xPaw commented Feb 5, 2019

Well the Reflection binary is where all the patches are.

@yaakov-h
Copy link
Member

Fixing [DefaultValue] seems like it should be a trivial PR to protobuf-net.

We can't easily implement service generation ourselves (by subclassing ProtoBuf.Reflection.CSharpCodeGenerator) because we need access to some private and internal members such as IType, NullIfInherit and FindNameFromCommonAncestor.

We can do it, but with reflection hackery and duplicated code copied from from protobuf-net.Reflection.

@mgravell Can we make those types/members part of public API, or do we have to upstream this, keeping in mind that it may conflict with / need to be switchable with gRPC as you mentioned in protobuf-net/protobuf-net#492?

In the meantime I'm tempted to proceed with reflection...

@xPaw
Copy link
Member Author

xPaw commented May 24, 2019

Closing in favor of #686

@xPaw xPaw closed this May 24, 2019
@xPaw xPaw deleted the update-protos branch June 18, 2020 20:52
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.

4 participants