Mapping C data structures and typedefs to .Net -


i'm trying write interface communicating network protocol, ieee document describes protocol @ bit level information split accross single byte.

what best way go handling c typedef such as

typedef struct {    nibble transportspecific;    enumeration4 messagetype;    uinteger4 versionptp;    uinteger16 messagelength;    uinteger8 domainnumber;    octet flagfield[2];    integer64 correctionfield;    portidentity sourceportidentity;    uinteger16 sequenceid;    uinteger8 controlfield;    integer8 logmessageinterval; } msgheader; 

when porting compatibility layer .net?

fieldoffsetattribute may of you, although there no way represent values smaller byte.

i use byte represent 2 values interop purposes, , access value via property getters.

unsafe struct msgheader {     public nibble transportspecific;     //enumeration4 messagetype;     //uinteger4 versionptp;     // use byte place holder these 2 fields     public byte union;     public ushort messagelength;     public byte domainnumber;     public fixed byte flagfield[2];     public long correctionfield;     public portidentity sourceportidentity;     public ushort sequenceid;     public byte controlfield;     public sbyte logmessageinterval;      // access value of 2 fields via getters     public byte messagetype { { return (byte)(union >> 4); } }     public byte versionptp { { return (byte)(union & 0xf); } } } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -