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

Support conversion of primitive values to pointer types. #42

Merged

Conversation

TristonianJones
Copy link
Collaborator

#35 Support conversion to pointer type for primitive values.

During proto2 message construction, primitive fields are set by pointer rather than
by value (as they are in proto3). This pull request ensures that primitive values can be
converted to pointer references.

ptrType := true
refType := reflect.TypeOf(&ptrType)
val, err := True.ConvertToNative(refType)
if err != nil || IsError(val) || !*val.(*bool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found only bool checks IsError(val). Does other types need to also check IsError(val)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, no, that was leftover from a previous test case that I'd copied. Removed.

ptrType := float32(0)
val, err := Double(3.1415).ConvertToNative(reflect.TypeOf(&ptrType))
if err != nil || *val.(*float32) != 3.1415 {
t.Errorf("Got '%v', wanted 3.1415", val)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err may need to be logged when err != nil

Copy link
Contributor

@madi8229 madi8229 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@TristonianJones TristonianJones merged commit b5faa5c into google:master Jun 8, 2018
@TristonianJones TristonianJones deleted the proto2-primitive-support branch June 8, 2018 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants