You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jens Geyer (JIRA)" <ji...@apache.org> on 2015/05/11 22:43:00 UTC
[jira] [Assigned] (THRIFT-3144) Proposal: make String
representation of enums in generated go code less verbose
[ https://issues.apache.org/jira/browse/THRIFT-3144?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jens Geyer reassigned THRIFT-3144:
----------------------------------
Assignee: Jens Geyer
> 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: Jens Geyer
>
> 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)