-- David B. Bitton [EMAIL PROTECTED] www.codenoevil.com
Code Made Fresh Daily™ ----- Original Message ----- From: "Marsh, Drew" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, May 10, 2002 6:08 PM Subject: Re: CopyMemory (RtlMoveMemory) -- The .NET way > 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. > imagine an example of a VB6 type: Private Type tdCTRLINFO lCtrlDate(1) As Integer lCtrlTime(1) As Integer lCtrlCount(1) As Integer End Type Private Type tdIFTPENDINGLIST CtrlInfo As tdCTRLINFO lTranId(1) As Integer nIsSendable As Integer nIsModifiable As Integer nFromAcctId As Integer sFromAcctNo As String * 20 nToAcctId As Integer sToAcctNo As String * 20 sAmount As String * 8 lSettlementDate(1) As Integer sStatus As String * 1 sFiller19 As String * 1 lFailCode(1) As Integer sFailMessage As String * 100 End Type we receive the binary data from our mainframe (which we affectionately refer to as the "cow", sacred that is). The process is to instatiate one of these types, and then lay the binary data over it. now, after my last post, i did some research and came up w/ System.BinaryConverter. Now, I need to use that, because if you notice, two of the integer values are an array. That's because we have a Big Endian/Little Endian conversion required. i also just read the list of members of the BinaryReader, and that looks quite promising. I guess that what I would need to do is just call the various Read... methods, plucking off the data as necessary (of course, i'd have to do some byte swapping, but that seems like a job better suited for a custom type that implements IConvertable). > 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. > can you expand on the reflection concept? i though reflection was reading a class's own metadata. > 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. > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.