Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-224

Validate method should check that enum types are assigned valid values

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • Ruby - Compiler
    • None
    • Patch Available

    Description

      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.

      Attachments

        1. thrift-224.patch
          3 kB
          Piotr Kozikowski
        2. thrift-224-v2.patch
          4 kB
          Piotr Kozikowski
        3. thrift-224-v3.patch
          2 kB
          Piotr Kozikowski
        4. thrift-224-v4.patch
          2 kB
          Piotr Kozikowski
        5. thrift-224-v5.patch
          1 kB
          Piotr Kozikowski
        6. thrift-224-v6.patch
          2 kB
          Piotr Kozikowski

        Issue Links

          Activity

            People

              pkozikow Piotr Kozikowski
              marz Nathan Marz
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: