Exemplo n.º 1
0
  public enum Label implements WireEnum {
    /** 0 is reserved for errors */
    LABEL_OPTIONAL(1),

    LABEL_REQUIRED(2),

    LABEL_REPEATED(3);

    public static final ProtoAdapter<Label> ADAPTER = ProtoAdapter.newEnumAdapter(Label.class);

    private final int value;

    Label(int value) {
      this.value = value;
    }

    /** Return the constant for {@code value} or null. */
    public static Label fromValue(int value) {
      switch (value) {
        case 1:
          return LABEL_OPTIONAL;
        case 2:
          return LABEL_REQUIRED;
        case 3:
          return LABEL_REPEATED;
        default:
          return null;
      }
    }

    @Override
    public int getValue() {
      return value;
    }
  }
Exemplo n.º 2
0
  public enum FooBarBazEnum implements WireEnum {
    FOO(1, 17, new More.Builder().serial(Arrays.asList(99, 199)).build(), null),

    BAR(2, null, null, true),

    BAZ(3, 18, null, false);

    public static final ProtoAdapter<FooBarBazEnum> ADAPTER =
        ProtoAdapter.newEnumAdapter(FooBarBazEnum.class);

    public static final EnumOptions ENUM_OPTIONS =
        new EnumOptions.Builder().enum_option(true).build();

    private final int value;

    public final Integer enum_value_option;

    public final More complex_enum_value_option;

    public final Boolean foreign_enum_value_option;

    FooBarBazEnum(
        int value,
        Integer enum_value_option,
        More complex_enum_value_option,
        Boolean foreign_enum_value_option) {
      this.value = value;
      this.enum_value_option = enum_value_option;
      this.complex_enum_value_option = complex_enum_value_option;
      this.foreign_enum_value_option = foreign_enum_value_option;
    }

    /** Return the constant for {@code value} or null. */
    public static FooBarBazEnum fromValue(int value) {
      switch (value) {
        case 1:
          return FOO;
        case 2:
          return BAR;
        case 3:
          return BAZ;
        default:
          return null;
      }
    }

    @Override
    public int getValue() {
      return value;
    }
  }
Exemplo n.º 3
0
  public enum Type implements WireEnum {
    /** 0 is reserved for errors. Order is weird for historical reasons. */
    TYPE_DOUBLE(1),

    TYPE_FLOAT(2),

    /** Not ZigZag encoded. Negative numbers */
    TYPE_INT64(3),

    /** take 10 bytes. Use TYPE_SINT64 if negative values are likely. */
    TYPE_UINT64(4),

    /** Not ZigZag encoded. Negative numbers */
    TYPE_INT32(5),

    /** take 10 bytes. Use TYPE_SINT32 if negative values are likely. */
    TYPE_FIXED64(6),

    TYPE_FIXED32(7),

    TYPE_BOOL(8),

    TYPE_STRING(9),

    /** Tag-delimited aggregate. */
    TYPE_GROUP(10),

    /** Length-delimited aggregate. */
    TYPE_MESSAGE(11),

    /** New in version 2. */
    TYPE_BYTES(12),

    TYPE_UINT32(13),

    TYPE_ENUM(14),

    TYPE_SFIXED32(15),

    TYPE_SFIXED64(16),

    /** Uses ZigZag encoding. */
    TYPE_SINT32(17),

    /** Uses ZigZag encoding. */
    TYPE_SINT64(18);

    public static final ProtoAdapter<Type> ADAPTER = ProtoAdapter.newEnumAdapter(Type.class);

    private final int value;

    Type(int value) {
      this.value = value;
    }

    /** Return the constant for {@code value} or null. */
    public static Type fromValue(int value) {
      switch (value) {
        case 1:
          return TYPE_DOUBLE;
        case 2:
          return TYPE_FLOAT;
        case 3:
          return TYPE_INT64;
        case 4:
          return TYPE_UINT64;
        case 5:
          return TYPE_INT32;
        case 6:
          return TYPE_FIXED64;
        case 7:
          return TYPE_FIXED32;
        case 8:
          return TYPE_BOOL;
        case 9:
          return TYPE_STRING;
        case 10:
          return TYPE_GROUP;
        case 11:
          return TYPE_MESSAGE;
        case 12:
          return TYPE_BYTES;
        case 13:
          return TYPE_UINT32;
        case 14:
          return TYPE_ENUM;
        case 15:
          return TYPE_SFIXED32;
        case 16:
          return TYPE_SFIXED64;
        case 17:
          return TYPE_SINT32;
        case 18:
          return TYPE_SINT64;
        default:
          return null;
      }
    }

    @Override
    public int getValue() {
      return value;
    }
  }