Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Distinguish between unset and explicitly set to default (proto2) #6

Open
benfrew13 opened this issue Apr 12, 2017 · 0 comments
Open

Comments

@benfrew13
Copy link

In a proto2 syntax message, an optional field set to the protobuf default value for that type can be distinguished from an unset field.

syntax = "proto2";

message Test {
    optional string name = 1;
}

If name is not set, calls to getName() will return the empty string, and calls to hasName() will return false.
If name is explicitly set to the empty string, hasName() will return true.

When run through Converter.toDomain() to an appropriately annotated class, the result is that name will be null regardless of whether or not name was set on the protobuf or not.

The converter should respect the value indicated by hasField() for proto2 syntax messages, and shouldn't nullify explicitly set fields, and should return null only if 'hasField()` returns false. For proto3, returning the default value for any given type would be more consistent with Google's implementation than attempting to return null.

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

1 participant