【发布时间】:2013-01-08 02:21:46
【问题描述】:
你好,我的结构如下
private struct MessageFormat
{
public byte[] Header; //start of message
public byte Fragmentation; //single packet or not
public byte Encryption; //encrypted message
public byte[] Authentication; //password
public byte[] Flag; //to locate end of auth
public byte[] Data; //info
public byte[] Trailer; //end of message
}
在我填充所有字段后,有没有一种方便的方法可以将整个 MessageFormat 转换为单字节数组[]?
【问题讨论】:
-
尝试查找 BitArray 类。
-
有一个方便的方法,但你可能不会喜欢它。 .NET 框架方式非常担心确保 byte[] 可以安全地转换回原始对象。不太方便的方法是 BinaryWriter。