-1

How can I add the properties of a proto message to get for example a total amount of summed up properties.

message Affordability {
   decimal salary = 1;
   decimal accomodation = 2;
   decimal phone_bill = 3;
   decimal utilities = 4;
}

Would like to calculate the TotalExpenses by adding all expenses and the substracting the value with the salary so as to derive the AmountLeft

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Chief_Muna
  • 27
  • 3
  • Are you talking about code gen? If you're not sure what I mean by this, please refer to [here](https://developers.google.com/protocol-buffers/docs/reference/csharp-generated). If so, please make that abundantly clear in your question so that we don't have to try and guess what you're talking about. – ProgrammingLlama Nov 11 '22 at 09:50

1 Answers1

0

Its going to depend a lot on what language you are using. Your should be sending the Affordability object to your server then it should just be a matter of calculating it as you have said.

public override Task<MathResult> TotalExpenses(Affordability request, ServerCallContext context)
    {
         
       var total = request.accomodation + request.phone_bill + request.utilities  ;


        var data = new MathResult()
        {
            AmountLeft = request.accomodation - total;
        };

        return Task.FromResult(data);
    }
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449