Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-4255

Go generator has type errors when in read/write functions for set<binary>

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.10.0
    • Fix Version/s: None
    • Component/s: Go - Compiler
    • Labels:
      None

      Description

      Given the following thrift definition:

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

      The following go code is generated:

      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
      }
      

      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.

        Attachments

        Issue Links

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              DavinC Davin Chia

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment