Code: Select all
Structure test
long.l
StructureOffset 0
firstByteOfLong.b
EndStructureOffset
StructureOffset 1
secondByteOfLong.b
EndStructureOffset
StructureOffset 2
theTwoLatestBytesOfLong.w
EndStructureOffset
EndStructure
I also want a StructureOffsetR for any relative position (read below).
I especially needed this when I wrote a server to handle remote control events from some iPhone application.
The data sent to my server was always 16 bytes and for neatness and ease of access I wanted to put this into a structure... But depending on what was sent the data could contain different values, most of the time the value I needed could be read as a word but sometimes I needed to read it as two bytes, below I will demonstrate what I mean.
Lets say that when command = 0 a relative x position is filled into the word relativePos, then I just read that value! But when command = 2 this means that a button has been pressed and the data at the position of relativePos now contains two values to be read as isPressed and buttonId. Get it? A StructureUnion wont help me with this...
Code: Select all
Structure data
command.b
relativePos.w
StructureOffsetR 0
isPressed.b
EndStructureOffset
StructureOffsetR 1
buttonId.b
EndStructureOffset
EndStructure
Did I finish my server without this YES, but it would be very sexy to be able to write structures like this!
Anyone understands and agree?