[
https://issues.apache.org/jira/browse/THRIFT-3144?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14537906#comment-14537906
]
ASF GitHub Bot commented on THRIFT-3144:
----------------------------------------
GitHub user kostya-sh opened a pull request:
https://github.com/apache/thrift/pull/489
THRIFT-3144 go: do not include enum name in string representation
Changed generated String/FromString methods for enums to use values from
thrift
definition file for string representation of an enum.
E.g.:
- before: String(TestEnum_FIRST) = "TestEnum_FIRST"
- after : String(TestEnum_FIRST) = "FIRST"
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/kostya-sh/thrift THRIFT-3144
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/thrift/pull/489.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #489
----
commit d0bc6079f9e308f5318e6d64482ac39462e3619c
Author: Konstantin Shaposhnikov <[email protected]>
Date: 2015-05-11T12:44:05Z
THRIFT-3144 go: do not include enum name in string representation
Changed generated String/FromString methods for enums to use values from
thrift
definition file for string representation of an enum.
E.g.:
- before: String(TestEnum_FIRST) = "TestEnum_FIRST"
- after : String(TestEnum_FIRST) = "FIRST"
----
> 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)