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

Konstantin Shaposhnikov commented on THRIFT-3144:
-------------------------------------------------

Pull request: https://github.com/apache/thrift/pull/489

> Proposal: make String representation of enums in generated go code less 
> verbose
> -------------------------------------------------------------------------------
>
>                 Key: THRIFT-3144
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3144
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Go - Compiler
>    Affects Versions: 0.9.2
>            Reporter: Konstantin Shaposhnikov
>
> Generated Go code for enums provides String() and EnumFromString methods for 
> enums. E.g.:
> {code}
>  func (p TestEnum) String() string {
>       switch p {
>       case TestEnum_FIRST:
>               return "TestEnum_FIRST"
>       case TestEnum_SECOND:
>               return "TestEnum_SECOND"
>       case TestEnum_THIRD:
>               return "TestEnum_THIRD"
>       case TestEnum_FOURTH:
>               return "TestEnum_FOURTH"
>       }
>       return "<UNSET>"
>  }
>  
>  func TestEnumFromString(s string) (TestEnum, error) {
>       switch s {
>       case "TestEnum_FIRST":
>               return TestEnum_FIRST, nil
>       case "TestEnum_SECOND":
>               return TestEnum_SECOND, nil
>       case "TestEnum_THIRD":
>               return TestEnum_THIRD, nil
>       case "TestEnum_FOURTH":
>               return TestEnum_FOURTH, nil
>       }
> }
> {code}
> The current implementation uses enum name as string representation. E.g. 
> String(TestEnum_FIRST) = "TestEnum_FIRST" which seems to be unnecessary 
> verbose to me.
> I propose to change it to use enum values from the thrift file instead. E.g.:
>  {code}
>  func (p TestEnum) String() string {
>       switch p {
>       case TestEnum_FIRST:
>               return "FIRST"
>       case TestEnum_SECOND:
>               return "SECOND"
>       case TestEnum_THIRD:
>               return "THIRD"
>       case TestEnum_FOURTH:
>               return "FOURTH"
>       }
>       return "<UNSET>"
>  }
>  
>  func TestEnumFromString(s string) (TestEnum, error) {
>       switch s {
>       case "FIRST":
>               return TestEnum_FIRST, nil
>       case "SECOND":
>               return TestEnum_SECOND, nil
>       case "THIRD":
>               return TestEnum_THIRD, nil
>       case "FOURTH":
>               return TestEnum_FOURTH, nil
>       }
> }
> {code}
> This is also consistent with generated code for other languages (e.g. Python, 
> C++).



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

Reply via email to