Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to differentiate unset value and zero value in protobuf3? #225

Closed
wanghq opened this issue Sep 1, 2016 · 2 comments
Closed

How to differentiate unset value and zero value in protobuf3? #225

wanghq opened this issue Sep 1, 2016 · 2 comments

Comments

@wanghq
Copy link

wanghq commented Sep 1, 2016

As described in https://developers.google.com/protocol-buffers/docs/reference/go-generated#singular-scalar-proto2, the field type changed from pointer to raw type.

For example, if I want to update a product's title but not the price, I can just set the Title and leave the Price unpopulated. How to achieve this without pointer (proto3)? Thanks.

// proto2
type Product struct {
  Title *string
  Price *int64
}
// proto3
type Product struct {
  Title string
  Price int64
}
@bcmills
Copy link
Contributor

bcmills commented Sep 1, 2016

proto3 does not allow application code to distinguish between unset and default scalar values. (This is true across proto3 implementations in all languages, not just in Go.)

For encoding incremental updates to messages, use FieldMask.

@bcmills bcmills closed this as completed Sep 1, 2016
@wanghq
Copy link
Author

wanghq commented Sep 2, 2016

Referencing this great discussion on issue setting empty values

@golang golang locked and limited conversation to collaborators Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants