ProtoBufJsonConverter 0.10.0.1
dotnet add package ProtoBufJsonConverter --version 0.10.0.1
NuGet\Install-Package ProtoBufJsonConverter -Version 0.10.0.1
<PackageReference Include="ProtoBufJsonConverter" Version="0.10.0.1" />
<PackageVersion Include="ProtoBufJsonConverter" Version="0.10.0.1" />
<PackageReference Include="ProtoBufJsonConverter" />
paket add ProtoBufJsonConverter --version 0.10.0.1
#r "nuget: ProtoBufJsonConverter, 0.10.0.1"
#addin nuget:?package=ProtoBufJsonConverter&version=0.10.0.1
#tool nuget:?package=ProtoBufJsonConverter&version=0.10.0.1
ProtoBufJsonConverter
This project uses protobuf-net to:
- Convert a protobuf message to a JSON string using the proto definition file.
- Convert a protobuf message to an object using the proto definition file.
- Convert a JSON string or an object to a protobuf message using the proto definition file.
- Get information about the package names, message types and C# namespaces in the proto definition file.
Usage
Proto Definition
syntax = "proto3";
// Package name
package greet;
// The greeting service definition.
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply);
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
1️⃣ Convert ProtoBuf byte[]
to a JSON string
Code
var protoDefinition = "...". // See above
var bytes = Convert.FromBase64String("CgRzdGVm");
var request = new ConvertToJsonRequest(protoDefinition, "greet.HelloRequest", bytes);
var converter = new Converter();
var json = await converter.ConvertAsync(request);
JSON
{"name":"stef"}
2️⃣ Convert ProtoBuf byte[]
to an object
Code
var protoDefinition = "...". // See above
var bytes = Convert.FromBase64String("CgRzdGVm");
var request = new ConvertToObjectRequest(protoDefinition, "greet.HelloRequest", bytes);
var converter = new Converter();
var @object = await converter.ConvertAsync(request);
3️⃣ Convert JSON string
to a ProtoBuf byte[]
Code
var protoDefinition = "...". // See above
var json = @"{""name"":""stef""}";
var request = new ConvertToProtoBufRequest(protoDefinition, "greet.HelloRequest", json);
var converter = new Converter();
var protobuf = await converter.ConvertAsync(request);
4️⃣ Convert any object
to a ProtoBuf byte[]
Code
var protoDefinition = "...". // See above
var obj = new
{
name = "stef"
};
var request = new ConvertToProtoBufRequest(protoDefinition, "greet.HelloRequest", obj);
var converter = new Converter();
var protobuf = await converter.ConvertAsync(request);
5️⃣ Convert any object
to a ProtoBuf byte[]
including the Grpc Header
Code
var protoDefinition = "...". // See above
var obj = new
{
name = "stef"
};
var request = new ConvertToProtoBufRequest(protoDefinition, "greet.HelloRequest", obj)
.WithGrpcHeader();
var converter = new Converter();
var protobufWithGrpcHeader = await ConvertAsync.Convert(request);
Using in Blazor WebAssembly
In order to use this library in a Blazor WebAssembly application, you need to provide a specific Blazor implementation for the IMetadataReferenceService
, the BlazorWasmMetadataReferenceService.
Convert ProtoBuf byte[]
to a JSON string
Dependency Injection
public class Program
{
public static async Task Main(string[] args)
{
// ...
// Add AddSingleton registrations for the IMetadataReferenceService and IConverter
builder.Services.AddSingleton<IMetadataReferenceService, BlazorWasmMetadataReferenceService>();
builder.Services.AddSingleton<IConverter, Converter>();
await builder.Build().RunAsync();
}
}
Blazor Page
public partial class Home
{
[Inject]
public required IConverter Converter { get; set; }
private State _state = State.None;
private string _protoDefinition = "..."; // See above
private string _messageType = "greet.HelloRequest";
private ConvertType _selectedConvertType = ConvertType.ToJson;
private string _protobufAsBase64 = "CgRzdGVm";
private bool _skipGrpcHeader = true;
private bool _addGrpcHeader = true;
private string _json = string.Empty;
private async Task OnClick()
{
await ConvertToJsonAsync();
}
private async Task ConvertToJsonAsync()
{
_json = string.Empty;
var bytes = Convert.FromBase64String(_protobufAsBase64);
var convertToJsonRequest = new ConvertToJsonRequest(_protoDefinition, _messageType, bytes)
.WithSkipGrpcHeader(_skipGrpcHeader)
.WithWriteIndented();
_json = await Converter.ConvertAsync(convertToJsonRequest);
}
}
For a full example, see examples/ProtoBufJsonConverter.Blazor.
6️⃣ Get information about the package names, message types and C# namespaces
Code
var protoDefinition = "...". // See above
var request = new GetInformationRequest(protoDefinition);
var response = await _sut.GetInformationAsync(request);
var packageNames = response.PackageNames;
var messageTypes = response.MessageTypes;
var namespaces = response.CSharpNamespaces;
💻 Examples
📚 Resources
Sponsors
Entity Framework Extensions and Dapper Plus are major sponsors and proud to contribute to the development of ProtoBufJsonConverter.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
.NET Framework | net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- MetadataReferenceService.Default (>= 0.0.1)
- Microsoft.CodeAnalysis.CSharp (>= 4.8.0)
- Newtonsoft.Json (>= 13.0.3)
- protobuf-net (>= 3.2.52)
- Stef.Validation (>= 0.1.1)
-
.NETFramework 4.8
- MetadataReferenceService.Default (>= 0.0.1)
- Microsoft.CodeAnalysis.CSharp (>= 4.8.0)
- Newtonsoft.Json (>= 13.0.3)
- protobuf-net (>= 3.2.52)
- Stef.Validation (>= 0.1.1)
-
.NETStandard 2.1
- MetadataReferenceService.Default (>= 0.0.1)
- Microsoft.CodeAnalysis.CSharp (>= 4.8.0)
- Newtonsoft.Json (>= 13.0.3)
- protobuf-net (>= 3.2.52)
- Stef.Validation (>= 0.1.1)
-
net6.0
- MetadataReferenceService.Default (>= 0.0.1)
- Microsoft.CodeAnalysis.CSharp (>= 4.8.0)
- Newtonsoft.Json (>= 13.0.3)
- protobuf-net (>= 3.2.52)
- Stef.Validation (>= 0.1.1)
-
net8.0
- MetadataReferenceService.Default (>= 0.0.1)
- Microsoft.CodeAnalysis.CSharp (>= 4.8.0)
- Newtonsoft.Json (>= 13.0.3)
- protobuf-net (>= 3.2.52)
- Stef.Validation (>= 0.1.1)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on ProtoBufJsonConverter:
Package | Downloads |
---|---|
WireMock.Net.Minimal
Minimal version from the lightweight Http Mocking Server for .NET |
|
VerticalField.VFS.MqttManager
Package Description |
|
WireMock.Net.ProtoBuf
ProtoBuf and gRPC support for WireMock.Net |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on ProtoBufJsonConverter:
Repository | Stars |
---|---|
wiremock/WireMock.Net
WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
|
Version | Downloads | Last updated |
---|---|---|
0.10.0.1 | 120 | 6/15/2025 |
0.10.0 | 107,740 | 5/18/2025 |
0.9.0 | 77,440 | 5/10/2025 |
0.8.0 | 78,481 | 5/5/2025 |
0.8.0-preview-01 | 144 | 5/4/2025 |
0.7.0 | 1,370,251 | 1/8/2025 |
0.7.0-preview-02 | 155 | 1/6/2025 |
0.7.0-preview-01 | 100 | 1/6/2025 |
0.6.0 | 289 | 1/3/2025 |
0.6.0-preview-03 | 167 | 1/3/2025 |
0.6.0-preview-02 | 143 | 1/3/2025 |
0.6.0-preview-01 | 139 | 1/2/2025 |
0.5.0 | 1,328,627 | 10/17/2024 |
0.4.0 | 186 | 10/15/2024 |
0.3.0 | 3,771,341 | 3/6/2024 |
0.2.0 | 290,196 | 2/9/2024 |
0.1.0 | 252 | 1/6/2024 |
0.0.6 | 347 | 12/28/2023 |
0.0.5 | 197 | 12/27/2023 |
0.0.4 | 210 | 12/25/2023 |
0.0.3 | 200 | 12/23/2023 |
0.0.2 | 172 | 12/22/2023 |
See CHANGELOG.md