ProtoBufJsonConverter 0.0.3
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 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"}
:one: Convert ProtoBuf byte[] to an object
Code
var protoDefinition = "...". // See above
var bytes = Convert.FromBase64String("CgRzdGVm");
var convertToObjectRequest = new ConvertToObjectRequest(protoDefinition, "greet.Greeter.SayHello", bytes);
var converter = new Converter();
var @object = converter.ConvertToJson(convertToObjectRequest);
:three: 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);
No packages depend on ProtoBufJsonConverter.
See CHANGELOG.md
.NET Framework 4.6.2
- AnyOf (>= 0.3.0)
- protobuf-net.Reflection (>= 3.2.12)
- protobuf-net (>= 3.2.30)
- Stef.Validation (>= 0.1.1)
- Microsoft.CodeAnalysis.CSharp (>= 4.8.0)
- JsonConverter.Newtonsoft.Json (>= 0.5.0)
.NET Standard 2.1
- protobuf-net.Reflection (>= 3.2.12)
- protobuf-net (>= 3.2.30)
- Stef.Validation (>= 0.1.1)
- Microsoft.CodeAnalysis.CSharp (>= 4.8.0)
- JsonConverter.Newtonsoft.Json (>= 0.5.0)
- AnyOf (>= 0.3.0)
.NET Standard 2.0
- protobuf-net.Reflection (>= 3.2.12)
- protobuf-net (>= 3.2.30)
- Stef.Validation (>= 0.1.1)
- JsonConverter.Newtonsoft.Json (>= 0.5.0)
- AnyOf (>= 0.3.0)
- Microsoft.CodeAnalysis.CSharp (>= 4.8.0)
.NET 6.0
- protobuf-net (>= 3.2.30)
- Stef.Validation (>= 0.1.1)
- Microsoft.CodeAnalysis.CSharp (>= 4.8.0)
- JsonConverter.Newtonsoft.Json (>= 0.5.0)
- AnyOf (>= 0.3.0)
- protobuf-net.Reflection (>= 3.2.12)
| Version | Downloads | Last updated |
|---|---|---|
| 0.10.0.1 | 2 | 10.07.2025 |
| 0.10.0 | 4 | 04.06.2025 |
| 0.9.0 | 5 | 02.06.2025 |
| 0.8.0 | 5 | 02.06.2025 |
| 0.8.0-preview-01 | 2 | 03.06.2025 |
| 0.7.0 | 7 | 19.03.2025 |
| 0.7.0-preview-02 | 4 | 19.03.2025 |
| 0.7.0-preview-01 | 5 | 19.03.2025 |
| 0.6.0 | 6 | 19.03.2025 |
| 0.6.0-preview-03 | 4 | 19.03.2025 |
| 0.6.0-preview-02 | 4 | 19.03.2025 |
| 0.6.0-preview-01 | 4 | 19.03.2025 |
| 0.5.0 | 6 | 19.03.2025 |
| 0.4.0 | 6 | 19.03.2025 |
| 0.3.0 | 6 | 19.03.2025 |
| 0.2.0 | 6 | 19.03.2025 |
| 0.1.0 | 5 | 19.03.2025 |
| 0.0.6 | 6 | 19.03.2025 |
| 0.0.5 | 6 | 19.03.2025 |
| 0.0.4 | 6 | 19.03.2025 |
| 0.0.3 | 6 | 19.03.2025 |
| 0.0.2 | 5 | 19.03.2025 |