David B. Bitton [mailto:[EMAIL PROTECTED]] wrote:
> Our application (VB6) receives a byte array via a TCP > conversation. We then take the byte array, and do a > CopyMemory into a UDT. This has been a classic way of > handling this type of situtation. Now, I want to know how I > would do this, the .NET way. > > How is this done? There's no (safe) way to just lay bytes over a piece of memory and then call it a type as it would entirely defeat the purpose of a type safe system. So, welcome to the CLR! ;) Do you only need to deserialize one type or do you need to be able to read many types? How extensible does your architecture be? I could suggest a bunch of solutions for hydrating the objects with the data, but some might be overkill. Check out BinaryReader[1]. The simplest solution is to just have a constructor on your type that takes a BinaryReader and then the type hydrates itself. A more advanced solution would be to use reflection, basically the way BinaryFormatter works. Unfortunately you can't just use BinaryFormatter straight out because it can only read write it's own proprietary streams of data. If you can control the sender of the bytes and the sender serializes using BinaryFormatter it would be really simple. HTH, Drew [1] ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemIOBinaryReaderClassTopic.h tm You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.
