.NETFramework4.6.2net6.0.NETStandard2.0.NETStandard2.1
Convert a protobuf message to a JSON string (and back) using the proto definition file.
Published
Dec 22, 2023
2y ago
Total Downloads
27.9M
27,905,610
Install
dotnet add package ProtoBufJsonConverter --version 0.0.2
| Product | Versions |
|---|---|
| .NET | |
| .NET Standard | |
| Other |
README
ProtoBufJsonConverter
- Convert a protobuf message to a JSON string using the proto definition file.
- Convert a JSON string to a protobuf message using 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;
}
:one: Convert ProtoBuf byte[] to a JSON string
Code
var protoDefinition = "...". // See above
var bytes = Convert.FromBase64String("CgRzdGVm");
var convertToJsonRequest = new ConvertToJsonRequest(protoDefinition, "greet.Greeter.SayHello", bytes);
var converter = new Converter();
var json = converter.ConvertToJson(convertToJsonRequest);
JSON
{"name":"stef"}
:two: Convert JSON string to a ProtoBuf byte[]
Code
var protoDefinition = "...". // See above
var json = @"{""name"":""stef""}";
var convertToProtoBufRequest = new ConvertToProtoBufRequest(protoDefinition, "greet.Greeter.SayHello", json);
var converter = new Converter();
var protobuf = converter.ConvertToProtoBuf(convertToProtoBufRequest);
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Compatibility metadata lists 4 target frameworks; confirm the exact target used by your application.The published metadata declares 20 direct dependency entries across framework groups. Inspect the resolved dependency graph for your target framework.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.