Binat Serialization With Headers

G

Guest

I'm trying to serialize an object across a tcp connection. I have the
foundation all set and now I'm trying to accomodate objects that might be
bigger than the receive buffer. So I figured I'd just use the serialization
header to hold some info about the size of the object and if it's got more
than one part. Then stream all the parts of an object into a single
MemoryStream and then deserialize the whole lot.

But when I started to implement it, I realized there were a few issues.

First, the Header array needs to be created before you serialize the object.
So I don't really have any way to check the size of the serialized object
beforehand, unless I serialize it twice. Once to check the size, and then
again to send it along with the header info that I populate once I know the
size fo the object.

Basically, I'm just looking for advice on how to handle objects bigger than
an expected receive buffer. How can I break them up and reassemble them on
the other side?

Thanks.
 
F

Frans Bouma [C# MVP]

rlrcstr said:
I'm trying to serialize an object across a tcp connection. I have
the foundation all set and now I'm trying to accomodate objects that
might be bigger than the receive buffer. So I figured I'd just use
the serialization header to hold some info about the size of the
object and if it's got more than one part. Then stream all the parts
of an object into a single MemoryStream and then deserialize the
whole lot.

But when I started to implement it, I realized there were a few
issues.

First, the Header array needs to be created before you serialize the
object. So I don't really have any way to check the size of the
serialized object beforehand, unless I serialize it twice. Once to
check the size, and then again to send it along with the header info
that I populate once I know the size fo the object.

Basically, I'm just looking for advice on how to handle objects
bigger than an expected receive buffer. How can I break them up and
reassemble them on the other side?

Look into the IDeserializationCallback interface. It makes the
formatter call your code when a class is deserialized in full. You then
could rebuild statistics in your header, as all data is available.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
G

Guest

But that's on the deserialize side, right? By then I'll already have to
have split the object up. I'll read through it, perhaps something will make
it clearer, but I find that the docs around this stuff are quite lacking.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top