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

Piotr Kozikowski updated THRIFT-223:
------------------------------------

    Attachment: thrift-223-v6.patch

Ok, I didn't notice that __isset was updated in the reader but not in the 
writer. The way I see it, it's not possible to know if a primitive type has 
been set in non-beans style, so the "// alas, we cannot check" branch is 
necessary. Here is an updated patch that does the following:

-field-values-getter on generated structs was removed
-beans style generated code remains the same
-for non-beans style, the validate method only checks for non-primitive 
required types, and the rest are checked only in the reader
-validate checks for valid enum values only for fields that are set in __isset, 
so in non-beans style it won't do the check unless the object was read 
(deserialized).

Also, I'm not sure I understand what you mean by "isset check" in "add a method 
to the generator that generates the isset check for a given field"

> Validate method should check that enum types are assigned valid values
> ----------------------------------------------------------------------
>
>                 Key: THRIFT-223
>                 URL: https://issues.apache.org/jira/browse/THRIFT-223
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Compiler (Java)
>            Reporter: Nathan Marz
>            Assignee: Piotr Kozikowski
>            Priority: Minor
>         Attachments: thrift-223-v2.patch, thrift-223-v3.patch, 
> thrift-223-v4.patch, thrift-223-v5.patch, thrift-223-v6.patch, 
> thrift-223.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.

Reply via email to