You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Bryan Duxbury (JIRA)" <ji...@apache.org> on 2009/01/16 23:35:59 UTC

[jira] Resolved: (THRIFT-224) Validate method should check that enum types are assigned valid values

     [ https://issues.apache.org/jira/browse/THRIFT-224?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryan Duxbury resolved THRIFT-224.
----------------------------------

    Resolution: Fixed

I just committed v5 with one small change. Instead of initializing VALID_VALUES with the constant values, I used the constant names. The result is functionally the same, but the generated code will look slightly prettier.

Thanks for the patch Piotr!

>  Validate method should check that enum types are assigned valid values
> -----------------------------------------------------------------------
>
>                 Key: THRIFT-224
>                 URL: https://issues.apache.org/jira/browse/THRIFT-224
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Compiler (Ruby)
>            Reporter: Nathan Marz
>            Assignee: Piotr Kozikowski
>         Attachments: thrift-224-v2.patch, thrift-224-v3.patch, thrift-224-v4.patch, thrift-224-v5.patch, thrift-224-v6.patch, thrift-224.patch
>
>
> The validate method generated currently checks that required fields are set. It would be nice if it were to enforce more parts of the schema. One example of this are the values assigned to enum types. For example, if I have this enum:
> enum MyEnum {
>  FOO = 1;
>  BAR = 3;
>  BAZ = 4;
>  BIZ = 5;
> } 
> and this struct:
> struct MyStruct {
>  MyEnum e;
> }
> The validate method would ensure that MyStruct#e is either 1, 3, 4, or 5.
> The naive way of implementing this would be to generate a conditional statement for every value, aka 
> "e==1 || e==3 || e==4 || e==5"
> A better implementation would generate something like:
> "e==1 || (e>=3 && e<=5)"
> Since the common case seems to be having large ranges of contiguous values, this is the difference between having N conditionals execute versus 2.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.