apache/thrift — pull request #62 by bensigelman (2013-10-30 22:07:05+00:00)
Title: make optional fields work in Golang

Hi Jens,
This is a [hopefully] minimal fix for https://issues.apache.org/jira/browse/THRIFT-2232.

For anyone else who's looking at this, the goal is to decouple the IsSet...() methods from the *values* of the fields they correspond to.

For example, prior to this change, an optional int with a value of `0` was considered absent per `IsSetXYZ()`. This is clearly broken, since `0` is often a valid value for a field.

The approach taken -- per the discussion on jira -- is to use pointers to fields within the generated Go structs.

A few notes about this approach:
- the existing code already used pointers for struct-valued fields, so now those are special-cased.
- since one cannot take the address of a temporary in Go, we must create some temporaries just to get pointers in certain situations.
- we did get to remove a big block of IsSet()-generation code, which is a nice bonus.

The new code works great for my company's project, though we don't use every thrift feature available. I generated all of the examples and tried to `go build` them; all of the example files that generated valid Go code prior to this change continue to do so after this change, though I don't see a full test suite to validate beyond that.

Thanks for your time and attention!
Ben