0

I have this Java enum that I need to interface with:

// Parameter.java
public enum Parameter {
    ExampleParameter1(45920L, 3, 127, ValueFormat.BINARY,       true),
    ExampleParameter2(45703L, 6, 6,   ValueFormat.NUMERIC,      true),
    ExampleParameter3(73L,    4, 4,   ValueFormat.ALPHANUMERIC, true),
    ExampleParameter3(4512L,  2, 11,  ValueFormat.ALPHANUMERIC, true);

    ( . . . )

    private ValueFormat a
    private int b;
    private long c;
    private boolean d;

    private Parameter(long tag, int param, int min, ValueFormat format, boolean boo)
    {
        this.a = format;
        this.b = min;
        this.c = tag;
        this.d = boo;
    }
}

I would like to generated a valid C++ <-> Java interface using Djinni, but since djinni's enums generate public enum in Java (correct in my case) and enum class in C++ (with int underlying type), it can't work.

Is this even possible? Or do I have to create a Djinni interface with Java and C++ implementation with manually-made "bindings"?

Thanks in advance for any help.

4
  • I am not sure what kind of interface is that supposed to be, and I don't even know what is Djinni. However, in a Java enum, you can definitely have some integer identifier and you can have a lookup by that identifier. If this helps you, I can give you a more detailed answer about that. Commented Oct 27, 2017 at 9:32
  • @Vlasec: Since this question is mainly about Djinni (which is a Java/C++/ObjC bridging helper, see here: github.com/dropbox/djinni), thanks for the offer but I don't think it would help me Commented Oct 27, 2017 at 9:37
  • I think stackoverflow is not the best place to ask questions about djinni. Did you try their slack channel mobilecpp.herokuapp.com ? Commented Oct 27, 2017 at 10:16
  • Java has always had its own weird notion of what an enum is and the general case doesn't correspond to an enum in any other language. Only the specific case where the enum just contains simple integer values corresponds to other languages. Commented Oct 28, 2017 at 3:40

1 Answer 1

1

This kind of enum containing many fields is a pretty unique concept to Java, while Djinni exposes the concept which is common across all languages, which supports an enum which has only an int value. If what you want is an object which contains multiple fields of various types, in Djinni you'll want a record. You can use an interface if you want to expose methods for custom behavior, but shouldn't need to for pure data.

In any case, Djinni generates its own types. It's not intended to directly expose existing types into other languages, so you'll need to write your own conversion function to turn your Parameter into a Djinni record, if you don't want to use the record directly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.