[ 
https://issues.apache.org/jira/browse/THRIFT-3533?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15111270#comment-15111270
 ] 

Jens Geyer commented on THRIFT-3533:
------------------------------------

{quote}
Looking at the Java code this looks quite similar, except the Java compiler 
does not generate it for the internal Arg structs.
{quote}

As you correctly recognized on your own, this is something different and not 
"quite similar". Exactly that test already existed before in Go, and your patch 
added what "the Java compiler does not generate": the test whether {{struct != 
nil}}.

{quote}
 I think that comes down to the *Args structs being written out using the same 
code paths as user defined structs.
{quote}

Could have been any struct, just happened to be that one. That's not really the 
point here. What about this:

{code}
func (p *FooBarStruct) Write(oprot thrift.TProtocol) error {

  if err := oprot.WriteStructBegin("foobar_args"); err != nil {   
     return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", 
p), err)
  }

  // if p is nil there is no content to write
  if( p !== nil) {
    if err := p.writeField1(oprot); err != nil {     
      return err
    }
    if err := p.writeField3(oprot); err != nil {    
      return err
    }
  }

  if err := oprot.WriteFieldStop(); err != nil {    
    return thrift.PrependError("write field stop error: ", err)
  }
  if err := oprot.WriteStructEnd(); err != nil {     
    return thrift.PrependError("write struct stop error: ", err)
  }

  return nil
}
{code}

That is simple, clear and everybody understands it. On top we don't need the 
uglyfication of the {{IsSet()}} members. 

What do you think? Do I overlook something?

PS: Of course, with either solution the other side will get an empty struct for 
every {{nil}} pointer that is considered "valid data".

> Can not send nil pointer as service method argument
> ---------------------------------------------------
>
>                 Key: THRIFT-3533
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3533
>             Project: Thrift
>          Issue Type: Bug
>          Components: Go - Compiler
>    Affects Versions: 0.9.3
>            Reporter: Chris Bannister
>         Attachments: 0001-go-compiler-handle-nil-fields-correctly.patch
>
>
> If you try to send a nil struct as an argument to a service method a panic 
> occurs as it tries to write out all the fields in the struct, the python 
> generated code has guarding 'if self.x != None:' for every struct field, 
> whereas Go only outputs the 'if p.IsSet()' when the field is declared 
> optional, which is not possible for argument lists.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to