How to emulate statically the C bitfields in c#?

Viewed 2367

I have to define a communication protocol and I want to use a bitfield to store some logic values.

I'm working on the both systems: the sender: a device and a .Net software as receiver.

On the firmware side, I defined as usually a bitfield struct like:

struct __attribute__((__packed__)) BitsField 
{
  // Logic values
  uint8_t vesselPresenceSw: 1;
  uint8_t drawerPresenceSw: 1;
  uint8_t pumpState: 1;
  uint8_t waterValveState: 1;
  uint8_t steamValveState: 1;
  uint8_t motorDriverState: 1;
    // Unused
  uint8_t unused_0: 1;
  uint8_t unused_1: 1;
};

How I can define a same structure on the software side that support a bytes deserialization to build the struct itself?

4 Answers
Related