Comments (4)
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.
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.
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.
Thank you for clarification. I'm closing this topic now.
from protobuf.
Related Issues (20)
- nil pointer error inside protobuf library. HOT 1
- Kotlin lite: Tried to write the same file twice
- How to cast descriptorpb.DescriptorProto to protoreflect.MessageDescriptor HOT 2
- Unwanted namespacing warning/ or error HOT 1
- Installation instructions for the common case (nit feature request) HOT 2
- marshall/unmarshal time.Time to *timestamppb.Timestamp fails HOT 8
- Add a generic proto.Clone HOT 1
- Support for optional fields HOT 2
- Latest version of google.golang.org/protobuf (v1.33.0) is no longer compatible with the latest version of github.com/golang/protobuf (v1.5.3) HOT 7
- Add option to JSON marshal / unmarshal: StripEnumPrefix / AddEnumPrefix HOT 10
- How to properly define protobuf `oneof` fields? HOT 2
- How can I import a pre-compiled proto from another package? HOT 4
- protodesc: feature "message_encoding" (in Protobuf editions) triggers proto2 group validation checks HOT 11
- timestamppb.AsTime is incorrectly implemented for nil/zero values HOT 2
- missing replace in go.mod HOT 1
- protojson: fail to unmarshal JSON with reserved fields HOT 19
- Parsing protoc plugin option containing ',' HOT 5
- go_features.proto has incorrect package and error-prone file path HOT 5
- Tracking issue: Fully Lazy Extension decoding HOT 7
- feature: Generate test client / `bufconn` constructors HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf.