-
Notifications
You must be signed in to change notification settings - Fork 505
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
Generate protobufs ourselves using protobuf-net.Reflection #686
Merged
Merged
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
e0aeec3
"Fine, I'll do it myself." - Thanos (2015)
yaakov-h bafad8d
Regen all protos
yaakov-h 7957b73
Update SteamKit to handle arrays instead of lists
yaakov-h 46ce9eb
Tenatively upstream some parts of service generation
yaakov-h 78425a6
Emit List<> for protobufs instead of Array.
yaakov-h 3384272
Regenerate protobufs
yaakov-h a041ace
Revert "Update SteamKit to handle arrays instead of lists"
yaakov-h f014dd7
Tentatively upstream another function
yaakov-h f05a5ab
Bail on actual proto errors
yaakov-h 9d7f6d4
wait this bit wasnt supposed to be staged
yaakov-h 21d4193
use stderr for warnings/errors, not stdout
yaakov-h 6375d3a
Reparse to avoid "no syntax specified" warning, ignore "import not us…
yaakov-h f0451b2
Fix whitespace (in powershell this time!)
yaakov-h cf7470d
Merge remote-tracking branch 'origin/experiment/protobuf-gen' into pr…
yaakov-h 86a9042
Log some assumption, fix an error path
yaakov-h d53a72a
Merge remote-tracking branch 'origin/master' into protobuf-gen-3
yaakov-h d236280
Add argument separator to dotnet command line
yaakov-h a69d544
Use protobuf-net alpha builds from NuGet
yaakov-h baec061
Regen all protobufs
yaakov-h 76a0e90
Update protobuf-net to latest stable
yaakov-h 9005a62
Emit proto services
yaakov-h 3764fe4
Regen proto services
yaakov-h a433229
Fix Samples build - DOTA hasn't had this msg for 10 months.
yaakov-h 096f41d
Update protobuf-net for NHA2
yaakov-h 4858fb4
DOTA still doesn't have this enum anymore
yaakov-h 53805da
Merge remote-tracking branch 'origin/master' into protobuf-gen-3
yaakov-h bad95d8
Un-comment commented code
yaakov-h 53d017b
Qualify aliased command
yaakov-h 055947f
Remove unused variable
yaakov-h ecc53b6
Build protobufgen before running it
yaakov-h File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="protobuf-net" version="2.1.0" targetFramework="net46" /> | ||
<package id="protobuf-net" version="2.4.1" targetFramework="net472" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.28803.352 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtobufGen", "ProtobufGen\ProtobufGen.csproj", "{DDC1D975-336F-4F3A-BCEA-D0DE5CEC6188}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{DDC1D975-336F-4F3A-BCEA-D0DE5CEC6188}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DDC1D975-336F-4F3A-BCEA-D0DE5CEC6188}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DDC1D975-336F-4F3A-BCEA-D0DE5CEC6188}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DDC1D975-336F-4F3A-BCEA-D0DE5CEC6188}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {31851CBB-4C49-402C-9F8B-42476FEDA58A} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using CommandLine; | ||
using Google.Protobuf.Reflection; | ||
|
||
namespace ProtobufGen | ||
{ | ||
static class Program | ||
{ | ||
public static int Main( string[] args ) | ||
{ | ||
var arguments = Parser.Default.ParseArguments<Options>( args ); | ||
switch ( arguments.Tag ) | ||
{ | ||
case ParserResultType.Parsed: | ||
var value = ( ( Parsed<Options> )arguments ).Value; | ||
return Run( value ); | ||
|
||
case ParserResultType.NotParsed: | ||
// The library will automatically write help text. | ||
return -1; | ||
|
||
default: | ||
// This should be unreachable. | ||
return int.MinValue; | ||
} | ||
} | ||
|
||
static int Run( Options arguments ) | ||
{ | ||
var set = ParseFiles( arguments ); | ||
|
||
if ( set == null ) | ||
{ | ||
return -1; | ||
} | ||
|
||
var errors = set.GetErrors(); | ||
PrintErrors( errors, out var numErrors, out var reparse ); | ||
|
||
if ( numErrors > 0 ) | ||
{ | ||
return numErrors; | ||
} | ||
else if ( reparse ) | ||
{ | ||
set = ReparseFiles( arguments, set ); | ||
errors = set.GetErrors(); | ||
PrintErrors( errors, out numErrors, out reparse ); | ||
|
||
Debug.Assert( numErrors == 0, "Errors should have been handled by first pass." ); | ||
Debug.Assert( !reparse, "Should not have to reparse after second pass." ); | ||
} | ||
|
||
var codegen = new SteamKitCSharpCodeGenerator(); | ||
|
||
var options = new Dictionary<string, string> | ||
{ | ||
[ "langver" ] = "7.0", | ||
[ "names" ] = "original", | ||
[ "services" ] = "1", | ||
}; | ||
|
||
var files = codegen.Generate( set, options: options ); | ||
var fileName = Path.GetFileName( arguments.ProtobufPath ); | ||
|
||
foreach ( var file in files ) | ||
{ | ||
if ( Path.GetFileNameWithoutExtension( file.Name ) != Path.GetFileNameWithoutExtension( fileName ) ) | ||
{ | ||
continue; | ||
} | ||
|
||
File.WriteAllText( arguments.Output, file.Text ); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static FileDescriptorSet ParseFiles( Options arguments ) | ||
{ | ||
var set = new FileDescriptorSet | ||
{ | ||
DefaultPackage = arguments.Namespace | ||
}; | ||
set.AddImportPath( Path.GetDirectoryName( arguments.ProtobufPath ) ); | ||
|
||
var fileName = Path.GetFileName( arguments.ProtobufPath ); | ||
if ( !set.Add( fileName, includeInOutput: true ) ) | ||
{ | ||
Console.Error.WriteLine( $"Could not find file '{fileName}'." ); | ||
return null; | ||
} | ||
|
||
set.Process(); | ||
return set; | ||
} | ||
|
||
static FileDescriptorSet ReparseFiles( Options arguments, FileDescriptorSet firstPass ) | ||
{ | ||
var set = new FileDescriptorSet | ||
{ | ||
DefaultPackage = firstPass.DefaultPackage | ||
}; | ||
|
||
set.AddImportPath( Path.GetDirectoryName( arguments.ProtobufPath ) ); | ||
|
||
foreach ( var file in firstPass.Files ) | ||
{ | ||
if ( string.IsNullOrEmpty( file.Syntax ) ) | ||
{ | ||
file.Syntax = "proto2"; | ||
} | ||
set.Files.Add( file ); | ||
} | ||
|
||
set.Process(); | ||
return set; | ||
} | ||
|
||
static void PrintErrors( ProtoBuf.Reflection.Error[] errors, out int numErrors, out bool reparse ) | ||
{ | ||
numErrors = 0; | ||
reparse = false; | ||
|
||
if ( errors.Length > 0 ) | ||
{ | ||
foreach ( var error in errors ) | ||
{ | ||
if ( error.IsError ) | ||
{ | ||
numErrors++; | ||
} | ||
|
||
if ( error.IsWarning && error.Message.StartsWith( "no syntax specified;" ) ) | ||
{ | ||
reparse = true; | ||
} | ||
else if ( !error.IsWarning || !error.Message.StartsWith( "import not used:" ) ) | ||
{ | ||
Console.Error.WriteLine( $"{error.File} ({error.LineNumber}, {error.ColumnNumber}): {error.Message}" ); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
class Options | ||
{ | ||
[Option( "namespace" )] | ||
public string Namespace { get; set; } | ||
|
||
[Option( "proto", Required = true )] | ||
public string ProtobufPath { get; set; } | ||
|
||
[Option( "output", Required = true )] | ||
public string Output { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CommandLineParser" Version="2.5.0" /> | ||
<PackageReference Include="protobuf-net.Reflection" Version="3.0.0-alpha.91" /> | ||
</ItemGroup> | ||
|
||
</Project> |
56 changes: 56 additions & 0 deletions
56
Resources/ProtobufGen/ProtobufGen/SteamKitCSharpCodeGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Google.Protobuf.Reflection; | ||
using ProtoBuf.Reflection; | ||
|
||
namespace ProtobufGen | ||
{ | ||
public class SteamKitCSharpCodeGenerator : CSharpCodeGenerator | ||
{ | ||
public SteamKitCSharpCodeGenerator() | ||
: base() | ||
{ | ||
} | ||
|
||
protected override bool UseArray( FieldDescriptorProto field ) => false; | ||
|
||
protected override void WriteExtension( GeneratorContext ctx, FieldDescriptorProto field ) | ||
{ | ||
} | ||
|
||
protected override void WriteExtensionsHeader( GeneratorContext ctx, DescriptorProto message, ref object state ) | ||
{ | ||
} | ||
|
||
protected override void WriteExtensionsHeader( GeneratorContext ctx, FileDescriptorProto file, ref object state ) | ||
{ | ||
} | ||
|
||
protected override void WriteExtensionsFooter( GeneratorContext ctx, DescriptorProto message, ref object state ) | ||
{ | ||
} | ||
|
||
protected override void WriteExtensionsFooter( GeneratorContext ctx, FileDescriptorProto file, ref object state ) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Starts a service block | ||
/// </summary> | ||
protected override void WriteServiceHeader( GeneratorContext ctx, ServiceDescriptorProto service, ref object state ) | ||
{ | ||
ctx.WriteLine( $"{GetAccess( GetAccess( service ) )} interface I{Escape( service.Name )}" ).WriteLine( "{" ).Indent(); | ||
} | ||
|
||
protected override void WriteServiceFooter( GeneratorContext ctx, ServiceDescriptorProto service, ref object state ) | ||
{ | ||
ctx.Outdent().WriteLine( "}" ).WriteLine(); | ||
} | ||
|
||
protected override void WriteServiceMethod( GeneratorContext ctx, MethodDescriptorProto method, ref object state ) | ||
{ | ||
var outputType = MakeRelativeName( ctx, method.OutputType ); | ||
var inputType = MakeRelativeName( ctx, method.InputType ); | ||
|
||
ctx.WriteLine( $"{Escape( outputType )} {Escape( method.Name )}({Escape( inputType )} request);" ); | ||
} | ||
} | ||
} |
42 changes: 21 additions & 21 deletions
42
Resources/Protogen/gc.proto → Resources/ProtobufGen/gc.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
enum GCProtoBufMsgSrc { | ||
GCProtoBufMsgSrc_Unspecified = 0; | ||
GCProtoBufMsgSrc_FromSystem = 1; | ||
GCProtoBufMsgSrc_FromSteamID = 2; | ||
GCProtoBufMsgSrc_FromGC = 3; | ||
GCProtoBufMsgSrc_ReplySystem = 4; | ||
} | ||
message CMsgProtoBufHeader { | ||
optional fixed64 client_steam_id = 1; | ||
optional int32 client_session_id = 2; | ||
optional uint32 source_app_id = 3; | ||
optional fixed64 job_id_source = 10 [default = 18446744073709551615]; | ||
optional fixed64 job_id_target = 11 [default = 18446744073709551615]; | ||
optional string target_job_name = 12; | ||
optional int32 eresult = 13 [default = 2]; | ||
optional string error_message = 14; | ||
optional uint32 ip = 15; | ||
optional .GCProtoBufMsgSrc gc_msg_src = 200 [default = GCProtoBufMsgSrc_Unspecified]; | ||
optional uint32 gc_dir_index_source = 201; | ||
} | ||
enum GCProtoBufMsgSrc { | ||
GCProtoBufMsgSrc_Unspecified = 0; | ||
GCProtoBufMsgSrc_FromSystem = 1; | ||
GCProtoBufMsgSrc_FromSteamID = 2; | ||
GCProtoBufMsgSrc_FromGC = 3; | ||
GCProtoBufMsgSrc_ReplySystem = 4; | ||
} | ||
|
||
message CMsgProtoBufHeader { | ||
optional fixed64 client_steam_id = 1; | ||
optional int32 client_session_id = 2; | ||
optional uint32 source_app_id = 3; | ||
optional fixed64 job_id_source = 10 [default = 18446744073709551615]; | ||
optional fixed64 job_id_target = 11 [default = 18446744073709551615]; | ||
optional string target_job_name = 12; | ||
optional int32 eresult = 13 [default = 2]; | ||
optional string error_message = 14; | ||
optional uint32 ip = 15; | ||
optional .GCProtoBufMsgSrc gc_msg_src = 200 [default = GCProtoBufMsgSrc_Unspecified]; | ||
optional uint32 gc_dir_index_source = 201; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file changed for no reason (line endings I assume?)
This also affected the csv file and the powershell script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only moved the files... possibly something in my git install tweaked the line endings?