-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
including but not limited to: - detect protobuf well-known types - detect NonUserCodeAttribute - detect ObsoleteAttribute to mark protobufs/fields as deprecated - parse generated client/server types for gRPC services - fix "optional" parsing - fix obfuscated name translation - fix foreign nested protobufs - support protobuf editions and corresponding options - rewrite protobuf models to better reflect the specification, including decoupling toplevels and files - rewrite a bunch of things to make more sense
- Loading branch information
Showing
24 changed files
with
1,173 additions
and
369 deletions.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,29 @@ | ||
// Copyright © 2024 Xpl0itR | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
namespace LibProtodec.Models.Fields; | ||
|
||
public sealed class EnumField | ||
{ | ||
public required string Name { get; init; } | ||
public required int Id { get; init; } | ||
|
||
public bool IsObsolete { get; init; } | ||
|
||
public void WriteTo(System.IO.TextWriter writer) | ||
{ | ||
writer.Write(Name); | ||
writer.Write(" = "); | ||
writer.Write(Id); | ||
|
||
if (IsObsolete) | ||
{ | ||
writer.Write(" [deprecated = true]"); | ||
} | ||
|
||
writer.WriteLine(';'); | ||
} | ||
} |
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,42 @@ | ||
// Copyright © 2024 Xpl0itR | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
using System.IO; | ||
using LibProtodec.Models.TopLevels; | ||
using LibProtodec.Models.Types; | ||
|
||
namespace LibProtodec.Models.Fields; | ||
|
||
public sealed class MessageField | ||
{ | ||
public required IType Type { get; init; } | ||
public required string Name { get; init; } | ||
public required int Id { get; init; } | ||
|
||
public bool IsObsolete { get; init; } | ||
public bool HasHasProp { get; init; } | ||
|
||
public void WriteTo(TextWriter writer, TopLevel topLevel, bool isOneOf) | ||
{ | ||
if (HasHasProp && !isOneOf && Type is not Repeated) | ||
{ | ||
writer.Write("optional "); | ||
} | ||
|
||
Protobuf.WriteTypeNameTo(writer, Type, topLevel); | ||
writer.Write(' '); | ||
writer.Write(Name); | ||
writer.Write(" = "); | ||
writer.Write(Id); | ||
|
||
if (IsObsolete) | ||
{ | ||
writer.Write(" [deprecated = true]"); | ||
} | ||
|
||
writer.WriteLine(';'); | ||
} | ||
} |
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,60 @@ | ||
// Copyright © 2024 Xpl0itR | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
using System.CodeDom.Compiler; | ||
using LibProtodec.Models.TopLevels; | ||
using LibProtodec.Models.Types; | ||
|
||
namespace LibProtodec.Models.Fields; | ||
|
||
public sealed class ServiceMethod | ||
{ | ||
public required string Name { get; init; } | ||
public required IType RequestType { get; init; } | ||
public required IType ResponseType { get; init; } | ||
|
||
public bool IsRequestStreamed { get; init; } | ||
public bool IsResponseStreamed { get; init; } | ||
public bool IsObsolete { get; init; } | ||
|
||
public void WriteTo(IndentedTextWriter writer, TopLevel topLevel) | ||
{ | ||
writer.Write("rpc "); | ||
writer.Write(Name); | ||
writer.Write(" ("); | ||
|
||
if (IsRequestStreamed) | ||
{ | ||
writer.Write("stream "); | ||
} | ||
|
||
Protobuf.WriteTypeNameTo(writer, RequestType, topLevel); | ||
writer.Write(") returns ("); | ||
|
||
if (IsResponseStreamed) | ||
{ | ||
writer.Write("stream "); | ||
} | ||
|
||
Protobuf.WriteTypeNameTo(writer, ResponseType, topLevel); | ||
writer.Write(')'); | ||
|
||
if (IsObsolete) | ||
{ | ||
writer.WriteLine(" {"); | ||
writer.Indent++; | ||
|
||
Protobuf.WriteOptionTo(writer, "deprecated", "true"); | ||
|
||
writer.Indent--; | ||
writer.WriteLine('}'); | ||
} | ||
else | ||
{ | ||
writer.WriteLine(';'); | ||
} | ||
} | ||
} |
Oops, something went wrong.