How are enums defined in Preon?

134 Views Asked by At

I am trying to use the preon I compiled from github (v 1.1) to parse the messages I get from an embedded C++ application. I included antlr 3.3-complete version in my project. I defined the following class as a header for network messages:

public class Header {
    @BoundNumber(byteOrder = org.codehaus.preon.buffer.ByteOrder.BigEndian)
    public MessageType MsgType;
    @BoundNumber(byteOrder = org.codehaus.preon.buffer.ByteOrder.BigEndian)
    public int MsgNo;
    @BoundNumber(byteOrder = org.codehaus.preon.buffer.ByteOrder.BigEndian)
    public int RspNo;
    @BoundNumber(byteOrder = org.codehaus.preon.buffer.ByteOrder.BigEndian)
    public int Length;
    }

MessageType enum is as follows:

public enum MessageType{
@BoundEnumOption(0x0000) Dummy1, 
@BoundEnumOption(0x0001) Dummy2
}

I try to cast the received network buffer as following:

Codec<Header> headerCodec = Codecs.create(Header.class);
Header h = Codecs.decode(headerCodec, headerData);
System.out.println(h);

I get the following antlr error. Is there something wrong with my definitions, or my included packages?

line 1:0 no viable alternative at input '< EOF >'

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

I found the problem. It seems for enumerations you have to explicitly provide a size value in BoundNumber annotation as following:

@BoundNumber(ByteOrder.BigEndian, size="32")
public MessageType MsgType;