code: public int encodedTypeLength() {
      int ans = 3; // 3 includes kind code for VARIANT plus the length
      for (int i = 0; i < cases.length; i++)
        ans += cases[i].encodedTypeLength();
      return ans;
    }
docs: Implementation of encodedTypeLength