thrift-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Davin Chia (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (THRIFT-4255) Go generator has type errors when in read/write functions for set<binary>
Date Thu, 20 Jul 2017 22:35:00 GMT

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

Davin Chia commented on THRIFT-4255:
------------------------------------

Seems this has been fixed in 
https://issues.apache.org/jira/browse/THRIFT-4011?jql=text%20~%20%22go%20set%22

> 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)

Mime
View raw message