This is a simple library that allows you to use decimal values in your protobuf messages.
It implements the approach described in ASP.NET documentation
syntax = "proto3";
package enhanced.protobuf;
option csharp_namespace = "Enhanced.Protobuf";
message DecimalValue {
int64 units = 1;
sfixed32 nanos = 2;
}
- Serialization and deserialization of decimal values.
- Implicit conversion between
decimal
andDecimalValue
.
dotnet add package Enhanced.Protobuf.DecimalValue
Define a message that uses DecimalValue
type.
syntax = "proto3";
import "enhanced/protobuf/DecimalValue.proto";
message Product {
string name = 1;
enhanced.protobuf.DecimalValue price = 2;
}
Use the generated C# classes in your code.
using Enhanced.Protobuf;
var product = new Product
{
Name = "Apple",
Price = 3.14m
};