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

Hudson commented on THRIFT-3144:
--------------------------------

SUCCESS: Integrated in Thrift #1543 (See 
[https://builds.apache.org/job/Thrift/1543/])
THRIFT-3144 make String representation of enums in generated go code less 
verbose (jensg: rev 77a7103fe189a6f7f909e3b665bdd5c669ced97c)
* compiler/cpp/src/generate/t_go_generator.cc
* lib/go/thrift/serializer_types.go


> 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
>            Assignee: Konstantin Shaposhnikov
>             Fix For: 0.9.3
>
>
> 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