我希望能夠組裝/ dissasemble字節的數據,如下面的僞代碼C#字節數組裝配
//Step one, how do I WriteInt, WriteDouble, WritString, etc to a list of bytes?
List<byte> mybytes = new List<byte>();
BufferOfSomeSort bytes = DoSomethingMagical(mybytes);
bytes.WriteInt(100);
bytes.WriteInt(120);
bytes.WriteString("Hello");
bytes.WriteDouble("3.1459");
bytes.WriteInt(400);
byte[] newbytes = TotallyConvertListOfBytesToBytes(mybytes);
//Step two, how do I READ in the same manner?
BufferOfAnotherSort newbytes = DoSomethingMagicalInReverse(newbytes);
int a = newbytes.ReadInt();//Should be 100
int b = newbytes.ReadInt();//Should be 120
string c = newbytes.ReadString();//Should be Hello
double d = newbytes.ReadDouble();//Should be pi (3.1459 or so)
int e = newbytes.ReadInt();//Should be 400
優秀!這正是我需要的! – 2012-01-29 00:13:23