Skip to content

Commit

Permalink
Update protobuf generator version, improve build, add readme (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 authored Sep 6, 2024
1 parent a5f6535 commit 8c93aae
Show file tree
Hide file tree
Showing 14 changed files with 1,528 additions and 51 deletions.
5 changes: 3 additions & 2 deletions src/libp2p/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<ProtobufVersion>3.28.0</ProtobufVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.13.11" />
<PackageVersion Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.11" />
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.4.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="Google.Protobuf" Version="3.25.1" />
<PackageVersion Include="Google.Protobuf.Tools" Version="3.25.1" />
<PackageVersion Include="Google.Protobuf" Version="$(ProtobufVersion)" />
<PackageVersion Include="Google.Protobuf.Tools" Version="$(ProtobufVersion)" />
<PackageVersion Include="Makaretu.Dns.Multicast" Version="0.27.0" />
<PackageVersion Include="Microsoft.CodeAnalysis" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.5.0" />
Expand Down
26 changes: 22 additions & 4 deletions src/libp2p/Libp2p.Core/Dto/KeyPair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public enum KeyType {
#endregion

#region Messages
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class PublicKey : pb::IMessage<PublicKey>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
Expand Down Expand Up @@ -265,7 +266,11 @@ public void MergeFrom(pb::CodedInputStream input) {
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
Expand All @@ -288,7 +293,11 @@ public void MergeFrom(pb::CodedInputStream input) {
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
Expand All @@ -307,6 +316,7 @@ public void MergeFrom(pb::CodedInputStream input) {

}

[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class PrivateKey : pb::IMessage<PrivateKey>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
Expand Down Expand Up @@ -522,7 +532,11 @@ public void MergeFrom(pb::CodedInputStream input) {
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
Expand All @@ -545,7 +559,11 @@ public void MergeFrom(pb::CodedInputStream input) {
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<RootNamespace>Nethermind.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<IsRoslynComponent>true</IsRoslynComponent>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<Version>$(ProtobufVersion)</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -46,7 +47,7 @@

<ItemGroup>
<AssemblyAttribute Include="Nethermind.Libp2p.Generators.Protobuf.ProtocLocation">
<_Parameter1>$(NuGetPackageRoot)google.protobuf.tools\3.24.1\tools\$(protoc)</_Parameter1>
<_Parameter1>$(NuGetPackageRoot)google.protobuf.tools\$(ProtobufVersion)\tools\$(protoc)</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

Expand Down
23 changes: 23 additions & 0 deletions src/libp2p/Libp2p.Generators.Protobuf/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
# Protobuf generator

The project automatically generates C# types for protobuf types using protoc(no need to install it separately, it's in the package).

## Usage

1. Add [Google.Protobuf](https://www.nuget.org/packages/Google.Protobuf) package
1. Add [Libp2p.Generators.Protobuf](https://www.nuget.org/packages/Nethermind.Libp2p.Generators.Protobuf) as analyzer dependency to you project
```xml
...
<ItemGroup>
...
<PackageReference Include="Libp2p.Generators.Protobuf" Version="3.25.1" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
...
```
1. Make sure that Google.Protobuf version matches Libp2p.Generators.Protobuf project version
1. Add a .proto file and set "Build Action" to "C# analyzer additional file" for it, "Copy to Output Directory"="Do not copy". It should look like
`<AdditionalFiles Include="Dto\Rpc.proto" CopyToOutputDirectory="Never" />` in csproj file.
1. .cs file should be generated next to .proto one.

## Additional notes

In case you want to use protobuf version that is more modern that is used by the generator, feel free to create an issue with request to update the version or just make a pr.
13 changes: 11 additions & 2 deletions src/libp2p/Libp2p.Protocols.Identify/Dto/Identify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static IdentifyReflection() {

}
#region Messages
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class Identify : pb::IMessage<Identify>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
Expand Down Expand Up @@ -373,7 +374,11 @@ public void MergeFrom(pb::CodedInputStream input) {
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
Expand Down Expand Up @@ -412,7 +417,11 @@ public void MergeFrom(pb::CodedInputStream input) {
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
Expand Down
52 changes: 44 additions & 8 deletions src/libp2p/Libp2p.Protocols.Noise/Dto/Exchange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public enum KeyType {
#endregion

#region Messages
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class Exchange : pb::IMessage<Exchange>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
Expand Down Expand Up @@ -268,7 +269,11 @@ public void MergeFrom(pb::CodedInputStream input) {
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
Expand All @@ -291,7 +296,11 @@ public void MergeFrom(pb::CodedInputStream input) {
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
Expand All @@ -310,6 +319,7 @@ public void MergeFrom(pb::CodedInputStream input) {

}

[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class NoiseExtensions : pb::IMessage<NoiseExtensions>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
Expand Down Expand Up @@ -472,7 +482,11 @@ public void MergeFrom(pb::CodedInputStream input) {
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
Expand All @@ -495,7 +509,11 @@ public void MergeFrom(pb::CodedInputStream input) {
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
Expand All @@ -514,6 +532,7 @@ public void MergeFrom(pb::CodedInputStream input) {

}

[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class PublicKey : pb::IMessage<PublicKey>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
Expand Down Expand Up @@ -729,7 +748,11 @@ public void MergeFrom(pb::CodedInputStream input) {
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
Expand All @@ -752,7 +775,11 @@ public void MergeFrom(pb::CodedInputStream input) {
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
Expand All @@ -771,6 +798,7 @@ public void MergeFrom(pb::CodedInputStream input) {

}

[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class NoiseHandshakePayload : pb::IMessage<NoiseHandshakePayload>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
Expand Down Expand Up @@ -1015,7 +1043,11 @@ public void MergeFrom(pb::CodedInputStream input) {
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
Expand Down Expand Up @@ -1045,7 +1077,11 @@ public void MergeFrom(pb::CodedInputStream input) {
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
Expand Down
13 changes: 11 additions & 2 deletions src/libp2p/Libp2p.Protocols.Plaintext/Dto/Exchange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static ExchangeReflection() {

}
#region Messages
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class Exchange : pb::IMessage<Exchange>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
Expand Down Expand Up @@ -249,7 +250,11 @@ public void MergeFrom(pb::CodedInputStream input) {
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
Expand All @@ -272,7 +277,11 @@ public void MergeFrom(pb::CodedInputStream input) {
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
Expand Down
Loading

0 comments on commit 8c93aae

Please sign in to comment.