Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
0.10.0
-
None
-
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
- Blocked
-
THRIFT-4011 Sets of Thrift structs generate Go code that can't be serialized to JSON
- Closed