Git Product home page Git Product logo

Comments (4)

neild avatar neild commented on July 19, 2024 1

protoreflect.Message.Get behaves mostly equivalently to accessor methods, which return the default value for unpopulated scalar fields. For example, in your case foo.GetField() returns "" if the field field is unset.

You can test to see if a field is set with foo.ProtoReflect().Has(paramField).

The protoreflect package operates on the protobuf data model, not the Go data model, so it doesn't have a concept of a field being nil. (For example, in generated messages, the representation of an unset optional string field is (*string)(nil), but a dynamicpb.Message uses a different representation. protoreflect can work with either.)

from protobuf.

puellanivis avatar puellanivis commented on July 19, 2024 1

The internal implementation of protoreflect.Value may need to consider things like a value being nil as it is sort of the “glue” between the protobuf data model, and the Go data model. But it only surfaces strictly the protobuf data model, and the internal Go data model is strictly an obscured implementation detail.

from protobuf.

honzap avatar honzap commented on July 19, 2024

Thanks for explanation. So my line of code getting to know isNil is basically correct, right?

For me, the curious thing is that protoreflect.Value inside works with nilType but basically, this can never happen, right?

from protobuf.

honzap avatar honzap commented on July 19, 2024

Thank you for clarification. I'm closing this topic now.

from protobuf.

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.