-
Notifications
You must be signed in to change notification settings - Fork 80
Encoding EnumType as ByteStream #83
Comments
Is there a way in which the enum-type elements can be accessed and compared? |
There isn't any way to iterate over enums in Ivy because enums aren't ordered. It would be a useful feature, though. Or instead just a way to cast between enums and integers. For now, though, there is no good way I can see to write a generic encoder for enumerated types. The closest thing I can think of is to define the order of the enum using an array, like this:
A slightly more efficient way to do this for large enums would be to also define an encoding map as a function (which is implemented as a hash table). Or just use a bit vector as your type and define a global variable for each value. Notice that I added a test action that checks that decoding is the inverse of encoding. If you compile this code with Also, if you use that above code, be sure to pull the latest code on the |
I have modified the use-case by adopting an Further, I have defined the enum-object-codec as follows. I intend to generate random messages of the following datagram using the
|
The problem is that the while loop in the initialiizer is an infinite loop. Change it to this:
I used this as a test action:
The last line just causes the log to be printed in hex. This is the result:
|
Thank you for your help with this issue. I had some difficulty in getting the codec to work, but I figured it out. |
I would like to encode an EnumType as a ByteStream, in the manner similar to
bv_encode
has been defined withinstream.ivy
. I am however, not clear about the way the Enum has been implemented.I'm raising this as a request to address the encoding and decoding of custom data-types that contain enumerated types.
I have written a small ivy-script that compiles successfully when executed individually. However, it fails when I test it by initializing objects.
The text was updated successfully, but these errors were encountered: