GitHub user bensigelman opened a pull request:

    https://github.com/apache/thrift/pull/62

    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

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/resonancelabs/thrift golang_optional_ptrs

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/thrift/pull/62.patch

----
commit 6f1e556192244736ee3a326b842aefddc6515483
Author: Ben Sigelman <b...@resonancelabs.com>
Date:   2013-10-30T21:24:24Z

    first cut at a fix for https://issues.apache.org/jira/browse/THRIFT-2232

----

Reply via email to