I have a class that needs to be serialized to a byte buffer. I'm using
a large, unwieldy, homegrown serialization method, which has to change
every time the class's members change, and I think there's probably a
better way.
I could do the job generically, and in just a few lines, by declaring
the class as [Serializable()], then using a BinaryFormatter to
serialize the object to a memory stream, then getting the buffer from
the memory stream. However, that generates a buffer that's much larger
than the actual size of the members in the class.
Is there an easy way of serializing the object to a byte buffer in a
space-efficient way? 5 1922
When you serialize a class using Serializable in .NET I believe it
breaks your class and it's valuables into XML, which is why it becomes
so large. As far as I know, that is the only utility in .NET to
serialize a class, and if you need something smaller you will have to
create it yourself. I feel your pain though as I have to support a
serialization method for a class that changes. dv*****@gmail.com wrote:
I have a class that needs to be serialized to a byte buffer. I'm using
a large, unwieldy, homegrown serialization method, which has to change
every time the class's members change, and I think there's probably a
better way.
I could do the job generically, and in just a few lines, by declaring
the class as [Serializable()], then using a BinaryFormatter to
serialize the object to a memory stream, then getting the buffer from
the memory stream. However, that generates a buffer that's much larger
than the actual size of the members in the class.
Is there an easy way of serializing the object to a byte buffer in a
space-efficient way?
justin creasy wrote:
When you serialize a class using Serializable in .NET I believe it
breaks your class and it's valuables into XML, which is why it becomes
so large. As far as I know, that is the only utility in .NET to
serialize a class, and if you need something smaller you will have to
create it yourself. I feel your pain though as I have to support a
serialization method for a class that changes.
dv*****@gmail.com wrote:
>I have a class that needs to be serialized to a byte buffer. I'm using a large, unwieldy, homegrown serialization method, which has to change every time the class's members change, and I think there's probably a better way.
I could do the job generically, and in just a few lines, by declaring the class as [Serializable()], then using a BinaryFormatter to serialize the object to a memory stream, then getting the buffer from the memory stream. However, that generates a buffer that's much larger than the actual size of the members in the class.
Is there an easy way of serializing the object to a byte buffer in a space-efficient way?
Hi Justin (and OP),
Not if you use the BinaryFormatter. The BinaryFormatter produces a binary
representation of the serialised class, i.e. in machine-readable form.
The reason that the resulting data is larger than simply the members in the
class is because it contains metadata required to deserialise the class
correctly, specifically versioning and type information.
--
Hope this helps,
Tom Spink
Google first, ask later.
Hey Tom, he actually is using the BinaryFormatter and his problem is
the overhead created by it. It's a great tool for rapid development,
but many times that overhead can become a big problem. As far as I
know, outside of the BinaryFormatter, the only way to have a low
overhead serialization function is to create it yourself. Please let me
know if I am missing something.
Tom Spink wrote:
justin creasy wrote:
When you serialize a class using Serializable in .NET I believe it
breaks your class and it's valuables into XML, which is why it becomes
so large. As far as I know, that is the only utility in .NET to
serialize a class, and if you need something smaller you will have to
create it yourself. I feel your pain though as I have to support a
serialization method for a class that changes. dv*****@gmail.com wrote:
I have a class that needs to be serialized to a byte buffer. I'm using
a large, unwieldy, homegrown serialization method, which has to change
every time the class's members change, and I think there's probably a
better way.
I could do the job generically, and in just a few lines, by declaring
the class as [Serializable()], then using a BinaryFormatter to
serialize the object to a memory stream, then getting the buffer from
the memory stream. However, that generates a buffer that's much larger
than the actual size of the members in the class.
Is there an easy way of serializing the object to a byte buffer in a
space-efficient way?
Hi Justin (and OP),
Not if you use the BinaryFormatter. The BinaryFormatter produces a binary
representation of the serialised class, i.e. in machine-readable form.
The reason that the resulting data is larger than simply the members in the
class is because it contains metadata required to deserialise the class
correctly, specifically versioning and type information.
--
Hope this helps,
Tom Spink
Google first, ask later.
Really, it shouldn't be too hard to roll-your-own
unsafe-binaryformatter that has no metadata, as long as you didn't mind
not using polymorphism and kept your classes in an a strict tree.
Horribly inappropriate for lobbing complex objects around, but would be
pretty sweet for passing structs around when you know what type to
expect. Just use reflection to iterate across the members (sort
members into an order though since order is undefined), serialize them
each individually into your stream, and call it done. Recurse where
you find a struct or class. The thing would stack-overflow if it
wasn't a strict tree though, and you'd have to use the default
Constructor() for the expected type, so no polymorphism unless you
roll-your-own metadata... but otherwise it should work.
justin creasy wrote:
Hey Tom, he actually is using the BinaryFormatter and his problem is
the overhead created by it. It's a great tool for rapid development,
but many times that overhead can become a big problem. As far as I
know, outside of the BinaryFormatter, the only way to have a low
overhead serialization function is to create it yourself. Please let me
know if I am missing something.
Tom Spink wrote:
justin creasy wrote:
When you serialize a class using Serializable in .NET I believe it
breaks your class and it's valuables into XML, which is why it becomes
so large. As far as I know, that is the only utility in .NET to
serialize a class, and if you need something smaller you will have to
create it yourself. I feel your pain though as I have to support a
serialization method for a class that changes.
> dv*****@gmail.com wrote:
>I have a class that needs to be serialized to a byte buffer. I'm using
>a large, unwieldy, homegrown serialization method, which has to change
>every time the class's members change, and I think there's probably a
>better way.
>>
>I could do the job generically, and in just a few lines, by declaring
>the class as [Serializable()], then using a BinaryFormatter to
>serialize the object to a memory stream, then getting the buffer from
>the memory stream. However, that generates a buffer that's much larger
>than the actual size of the members in the class.
>>
>Is there an easy way of serializing the object to a byte buffer in a
>space-efficient way?
Hi Justin (and OP),
Not if you use the BinaryFormatter. The BinaryFormatter produces a binary
representation of the serialised class, i.e. in machine-readable form.
The reason that the resulting data is larger than simply the members in the
class is because it contains metadata required to deserialise the class
correctly, specifically versioning and type information.
--
Hope this helps,
Tom Spink
Google first, ask later.
justin creasy wrote:
Hey Tom, he actually is using the BinaryFormatter and his problem is
the overhead created by it. It's a great tool for rapid development,
but many times that overhead can become a big problem. As far as I
know, outside of the BinaryFormatter, the only way to have a low
overhead serialization function is to create it yourself. Please let me
know if I am missing something.
Tom Spink wrote:
>justin creasy wrote:
When you serialize a class using Serializable in .NET I believe it
breaks your class and it's valuables into XML, which is why it becomes
so large. As far as I know, that is the only utility in .NET to
serialize a class, and if you need something smaller you will have to
create it yourself. I feel your pain though as I have to support a
serialization method for a class that changes.
dv*****@gmail.com wrote: I have a class that needs to be serialized to a byte buffer. I'm using a large, unwieldy, homegrown serialization method, which has to change every time the class's members change, and I think there's probably a better way.
I could do the job generically, and in just a few lines, by declaring the class as [Serializable()], then using a BinaryFormatter to serialize the object to a memory stream, then getting the buffer from the memory stream. However, that generates a buffer that's much larger than the actual size of the members in the class.
Is there an easy way of serializing the object to a byte buffer in a space-efficient way?
Hi Justin (and OP),
Not if you use the BinaryFormatter. The BinaryFormatter produces a binary representation of the serialised class, i.e. in machine-readable form.
The reason that the resulting data is larger than simply the members in the class is because it contains metadata required to deserialise the class correctly, specifically versioning and type information.
-- Hope this helps, Tom Spink
Google first, ask later.
Justin,
I meant to infer that serialising the class does not necessarily produce
XML. Your post seemed to imply that serialisation produced XML. Using a
BinaryFormatter, no XML is produced.
--
Hope this helps,
Tom Spink
Google first, ask later. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Michael Rozdoba |
last post by:
I'm far from a CSS expert, but what I see of it I really like & I love
keeping content & style separate. I also hate the way table layout
produces convoluted bulky code.
However when asked why...
|
by: Fuzzy via .NET 247 |
last post by:
I have a struct that I would like to control the field layout on in the same manner of UNION structs in C++.
This is not for passing data to unmanaged code, it is to save memory space because field...
|
by: barcaroller |
last post by:
Is it legal to compare the contents of two multi-field variables (of the
same struct) using "==" and "!="?
struct
{
int a;
int b;
} x,y;
...
|
by: Daniel Rudy |
last post by:
What is the difference between packed and unpacked structs?
--
Daniel Rudy
Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m
Why...
|
by: Chris Ashley |
last post by:
I have an array of structs which I am serializing. Is there a tag I can
use to change the name of the struct members in the output XML? I know
I can change the root node name with:
private...
|
by: ravi.sathyam |
last post by:
Hey,
So say I have a sockaddr_in struct stored in a packet which I receive
from my udp socket.....and it is stored within a certain offset into
this packet (which is basically a char array)....
|
by: JohnQ |
last post by:
Are a default constructor, destructor, copy constructor and assignment
operator generated by the compiler for a struct if they are not explicitely
defined?
I think the answer is yes, because...
|
by: Cagdas Ozgenc |
last post by:
Greetings,
When directly serializing C++ structures to a file with the standard
library functions giving the address of the data and length of
structure using the sizeof operator, do I risk...
|
by: dans |
last post by:
I want to serialise an array of structs into a MemoryStream so I can pass the contents in a message.
I have written something that will Serialize and Deserialize in individual object. Is there a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| | |