It might be a dumb question, but I haven't found anything yet about this.
I'm trying to update my rabbitmq code, and I've got a problem with case types. The AMQP protocol is using uint32 coding of command group(high 16 bits)/command(lower 16 bits) and such a coding perfectly lays upon the case types, but I'm continuosly getting the three errors:
I've investigated the nim generated C-code and I can't really understand those restrictions. There are a simple switch/case construction and my int16 enums are even downcasted to uint8 (no problem with that). The case type is a simple union of structs. Both things are not subjected to any of above restrictions IMO.
The questions are:
(writing lowlevel protocol parsing code in nim with that restrictions is a pain) :(
It used to be the case that the compiler produced lookup tables rather than switch statements and these tables work better when they are not gigantic.
That said, for "low level protocol parsing code" write low level protocol parsing code:
template group(x: uint32): uint32 = x shr 16u32
template cmd(x: uint32): uint32 = x and 0xffff'u32
Or maybe use the .union pragma.
I've seen the C-code and there are only switch/case code without lookup tables in my case. The variant type is just a union with several structs inside.
The problem is not in splitting the 32 to 2x16 (easy using .union), but setting type variant for that command. The case type can't be simply mapped to cmd id, but needs to be converted because of those limitations of nim compiler.
I need now to store 2 elements for each command group: