R
Roy Chastain
I have a legacy structure that appears on a communications line that has 16 bit, 8 bit, 2 bit and 1 bit fields in it.
The best I have been able to do with this was to use FieldOffset for the 8 and 16 bit fields. I then defined enums with the
FlagAttribute to generate the 1 and 2 bit fields.
Any suggestions or comments on the preceding are welcome.
Now, things get better.
As I said this structure comes on a communications line so if a BYTE (8 bits) contains certain invalid binary data, it is
escaped.with an escape BYTE. In my old C++ code, I simply allocated a structure of the correct size and copied the incoming bytes
to it skipping the escape bytes. For example, I might receive 40 bytes of data for the 36 bytes structure and 4 of the 40 bytes
would be escape bytes. After copy and dropping escape bytes, I would have 36 bytes in the correct location to access via C++
field names.
I need a way to do this C#. I would prefer to keep it as safe code. I am not sure that this code will be able to run everywhere
that it needs to run if it is unsafe.
I could do the same copy and drop using byte arrays, but I do not know how to get my 36 byte array into the structure.
Thanks for help and pointers.
The best I have been able to do with this was to use FieldOffset for the 8 and 16 bit fields. I then defined enums with the
FlagAttribute to generate the 1 and 2 bit fields.
Any suggestions or comments on the preceding are welcome.
Now, things get better.
As I said this structure comes on a communications line so if a BYTE (8 bits) contains certain invalid binary data, it is
escaped.with an escape BYTE. In my old C++ code, I simply allocated a structure of the correct size and copied the incoming bytes
to it skipping the escape bytes. For example, I might receive 40 bytes of data for the 36 bytes structure and 4 of the 40 bytes
would be escape bytes. After copy and dropping escape bytes, I would have 36 bytes in the correct location to access via C++
field names.
I need a way to do this C#. I would prefer to keep it as safe code. I am not sure that this code will be able to run everywhere
that it needs to run if it is unsafe.
I could do the same copy and drop using byte arrays, but I do not know how to get my 36 byte array into the structure.
Thanks for help and pointers.