Serialization


Author
Message
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Sure.  If I were going to do this I would put it in the front of the byte array with any information that will tell me where the serialized BO starts, etc.  So the beginning of the byte array would be a "header" that contained whatever information that you needed.  This is why I mentioned that resetting the memory stream was not a safe thing to do as other people may be using the memory stream for other things.
Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Trent L. Taylor (03/14/2009)
Sure. If I were going to do this I would put it in the front of the byte array with any information that will tell me where the serialized BO starts, etc. So the beginning of the byte array would be a "header" that contained whatever information that you needed. This is why I mentioned that resetting the memory stream was not a safe thing to do as other people may be using the memory stream for other things.


Yes, but can you give me a sample code of how to add the info to the byte array? in my case I will enter the code at the end of the array and the communication library will take care of removing it from the transferred stream.

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Hmmm....it is going to be a lot mroe difficult to add it at the end as you will not know the length of the serialized BO.  That is why a header would work much better as you would know what to expect that tells you what is further down the stream.
Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Trent L. Taylor (03/15/2009)
Hmmm....it is going to be a lot mroe difficult to add it at the end as you will not know the length of the serialized BO.  That is why a header would work much better as you would know what to expect that tells you what is further down the stream.

Hi again,

Thanks, but could you provide a quick sample code on how to add this byte to the header?  sorry, but I am really lost here w00t

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Well, it would just be a matter of creating your header in a string format, etc.  Then place that header at the beginning.  For example, I might have an enum that tells me the contents of the byte array in the first element.  In this case, a "1" would indicate a business object.  You could make this as long as you need since you would be in control of the header.  The second part of the header may indicate, in bytes, the length of the serialized BO.

Dim header As String = "1|"
Dim bo() As Byte
Dim mem As New System.IO.MemoryStream()
Dim headerInBytes() As Byte

'-- Serialize the BO to a byte array
bo = MyBO.SerializeToByteArray()

'-- Create the header
header &= bo.Length.ToString()

'-- Place an ending tag on the header
header &= "|"

headerInBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(header)

'-- Create the full byte array
mem.Write(headerInBytes, 0, headerinBytes.Length)

'-- Add the BO to the byte array
mem.Write(bo, 0, bo.Length)

'-- Convert the stream into a byte array
mem.Seek(0, Begin)
Dim r() As Byte = mem.ToArray()

So when you get the byte array on the server side (or whereever) you already know what to expect in the header.  So you can parse it out of the array (convert it back into a string or whatever you expect) and then you know what to do with the rest of the array.

Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Thanks a lot Trent, that will get me started.

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search