You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Davin Chia (JIRA)" <ji...@apache.org> on 2017/07/18 04:07:00 UTC

[jira] [Created] (THRIFT-4255) Go generator has type errors when in read/write functions for set

Davin Chia created THRIFT-4255:
----------------------------------

             Summary: Go generator has type errors when in read/write functions for set<binary>
                 Key: THRIFT-4255
                 URL: https://issues.apache.org/jira/browse/THRIFT-4255
             Project: Thrift
          Issue Type: Bug
          Components: Go - Compiler
    Affects Versions: 0.10.0
            Reporter: Davin Chia


Given the following thrift definition:

{code:java} struct CustomSet {
  1: required set<binary> values;
}{code}

The following go code is generated:
{code:java}
type CustomSet struct {
  Values map[string]struct{} `thrift:"values,1,required" db:"values" json:"values"`
}

func (p *ByteArraySet)  ReadField1(iprot thrift.TProtocol) error {
  _, size, err := iprot.ReadSetBegin()
  if err != nil {
    return thrift.PrependError("error reading set begin: ", err)
  }
  tSet := make(map[string]struct{}, size)
  p.Values =  tSet
  for i := 0; i < size; i ++ {
var _elem2 []byte
    if v, err := iprot.ReadBinary(); err != nil {
    return thrift.PrependError("error reading field 0: ", err)
} else {
    _elem2 = v
}
    p.Values[_elem2] = struct{}{}
  }
  if err := iprot.ReadSetEnd(); err != nil {
    return thrift.PrependError("error reading set end: ", err)
  }
  return nil
}

func (p *ByteArraySet) writeField1(oprot thrift.TProtocol) (err error) {
  if err := oprot.WriteFieldBegin("values", thrift.SET, 1); err != nil {
    return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:values: ", p), err) }
  if err := oprot.WriteSetBegin(thrift.STRING, len(p.Values)); err != nil {
    return thrift.PrependError("error writing set begin: ", err)
  }
  for v, _ := range p.Values {
    if err := oprot.WriteBinary(v); err != nil {
    return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err) }
  }
  if err := oprot.WriteSetEnd(); err != nil {
    return thrift.PrependError("error writing set end: ", err)
  }
  if err := oprot.WriteFieldEnd(); err != nil {
    return thrift.PrependError(fmt.Sprintf("%T write field end error 1:values: ", p), err) }
  return err
}
{code}

In the *Read* function, *elem_2* needs to be cast to *string* before its used as a key to *Values*.
In the *Write* function, *v* needs to be case to *byte[]* before its passed to *WriteBinary*.

I have opened a couple of issues today and will slowly work through them as time frees up.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)