Home > Net >  Help me put a C structure into the structure of C # (union)
Help me put a C structure into the structure of C # (union)

Time:09-19

Enum Law
{
Law_ULaw=0,/* * & lt; U law */
Law_ALaw=1,/* * & lt; A law */
Law_PCM16=2,/* * & lt; 16 bit uniform PCM values. The raw PCM data */
Law_G726=3/* * & lt; G726 */
};

What Bits///* */
Enum Rate
{
Rate16kBits=2,/* * & lt; 16 k bits per second (2 bits per ADPCM sample) */
Rate24kBits=3,/* * & lt; 24 k bits per second (3 bits per ADPCM sample) */
Rate32kBits=4,/* * & lt; 32 k bits per second (4 bits per ADPCM sample) */
Rate40kBits=5/* * & lt; 40 k bits per second (5 bits per ADPCM sample) */
};

Typedef struct _g711param
{
;
} G711Param;

Typedef struct _g726param
{
Unsigned char ucRateBits;//Rate16kBits Rate24kBits Rate32kBits Rate40kBits
} G726Param;

Typedef struct _initParam
{
Unsigned char ucAudioCodec;//Law_uLaw Law_ALaw Law_PCM16 Law_G726
Unsigned char ucAudioChannel;//1
Unsigned int u32AudioSamplerate;//8000
Unsigned int u32PCMBitSize;//16
The union
{
G711Param G711Param;
G726Param G726Param;
};

} InitParam; How special is the last struct InitParam into c #

CodePudding user response:

One way is to use LayoutKind. Explicit and FieldOffset,
See example:

[how to implement complex union in c + + c #]
https://bbs.csdn.net/topics/340259891

CodePudding user response:

Typedef struct _initParam
{
Unsigned char ucAudioCodec;//Law_uLaw Law_ALaw Law_PCM16 Law_G726
Unsigned char ucAudioChannel;//1
Unsigned int u32AudioSamplerate;//8000
Unsigned int u32PCMBitSize;//16
The union
{
G711Param G711Param;
G726Param G726Param;
}; The union of struct in c # how to write??????? Help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  •  Tags:  
  • C#
  • Related