-
SOS:: Structure Sizes to Byte Arrays!
Hi!
I need to copy a structure into a byte array so that I can send it over a
socket. But I have been having *problems*.
Here is a runthru' of what I'm doing..
I need byte alignment - so I have the attributes defined before the struct.
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi, Pack=1)]
struct aStruct
{
public int field1;
public int field2;
public int field3;
public int field4;
}
However, when I have to convert the struct into a byte stream for writing to
the socket, I cannot figure out how to convert the struct to a byte array
except by converting the object to a string and then to a byte array - this
way I get the size of the struct as 32 bytes while it should be 16 bytes.
How do I get the exact no. of bytes?!!?
Please help!
Thanks and regards
gautam
--
Realize your limitations. Then go beyond them.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks