Giter Site home page Giter Site logo

Comments (5)

splittingred avatar splittingred commented on July 24, 2024

Hi @travisofthenorth - fields in Protobuf are always optional - meaning that any unspecified value will always be nil if not passed. This allows you to do proper presence checks, which allow partial updates to happen.

For instance, take a description - field:

message Product {
   uint64 id = 1;
   string name = 2;
   string description = 3;
}

Lets say I wanted to update Product, but didn't want to touch the description. Right now, description is a native string, which means it will always come over as a string. This means if not set by the client, it will come as "". That's problematic for us, as how would the client differentiate between an empty description (a valid value!) and one not passed?

Google provides wrapper types, such as Google::Protobuf::StringValue, to help with this. Lets change our message:

message Product {
   uint64 id = 1;
   google.protobuf.StringValue name = 2;   
   google.protobuf.StringValue description = 3;
}

Now, we can pass either the name or description optionally, and in our code check for nil to see if the client meant to update that field.

So, in other words - this behavior is expected and intentional. Thanks!

from gruf.

travisofthenorth avatar travisofthenorth commented on July 24, 2024

@splittingred I'm explicitly passing in Google::Protobuf::Int32Value.new(value: 0)

from gruf.

travisofthenorth avatar travisofthenorth commented on July 24, 2024

In any case, another one of my clients doesn't seem to have this problem, so it must be something silly like a gem version in the particular client I'm looking at.

Thanks for taking a look, and apologies for the false alarm!

from gruf.

travisofthenorth avatar travisofthenorth commented on July 24, 2024

If anyone encounters this error again, this was a bug in protobuf fixed here: protocolbuffers/protobuf#7195

from gruf.

splittingred avatar splittingred commented on July 24, 2024

@travisofthenorth Oh! Interesting, I misunderstood your question then (didn't realize you were asking about the wrapper value vs the main message).

Thanks for linking the protobuf fix. Appreciate it!

from gruf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.