473,406 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Need Help deserializing Binary Field in C++

Hi All -

I am creating a upgrade utility that transfers an bin / exe image over an
xml stream. But I can not seem to get the deserialization of the binary
field to work correctly. What I have is a base 64 encoded field but when I
try to deserialize, I throw an XML / reflection exception. However, if I
remove the base64 (m_Data) stuff everything works fine. I clearly have a
problem with my m_Data set-up. Does anybody know how to do this? What are
the corrrect data type and attributes?

// TEST SML STRING
String* xmlstr = "<?xml
version=\"1.0\"?><VersionMap><Packages><Firmware>< Description>Firmware Ver
1.2.1200</Description><ID>1000</ID><Size>419292</Size><Signature>ver.1.2.1200Beta</Signature><Data>BASE64ENCODEDDATAGOESHERE</Data><MIB><Size>548</Size></MIB></Firmware><Firmware><Description>Firmware
Ver
1.3.1352</Description><ID>1000</ID><Size>42121</Size><Signature>ver.1.3.1352</Signature><Data>BASE64ENCODEDDATAGOESHERE</Data><MIB><Size>643</Size></MIB></Firmware></Packages></VersionMap>";

// DESERIALIZE HERE (Host::Utils::Xml::Deserialize is my serialization /
deserialization wrapper - I think this works correctly)
MVersionMap* VersionMap =
dynamic_cast<MVersionMap*>(Host::Utils::Xml::Deser ialize(xmlstr,
__typeof(MVersionMap)));

//
//MIB Class
public __gc class MMib
{
public:
MMib()
: m_Size (0)
{}
[XmlElement(DataType="unsignedInt", ElementName=S"Size", Namespace=S"",
Form=Schema::XmlSchemaForm::Unqualified, IsNullable=false)]
UInt32 m_Size;
};

// Firmware Class
public __gc class MFirmware
{
public:
MFirmware()
: m_Description (S"")
, m_ID (0)
, m_Size (0)
, m_Signature (S"")
, m_Mib (NULL)
{
}
[XmlElement(DataType="string", ElementName=S"Description", Namespace=S"",
Form=Schema::XmlSchemaForm::Unqualified, IsNullable=false)]
String* m_Description;
[XmlElement(DataType="unsignedInt", ElementName=S"ID", Namespace=S"",
Form=Schema::XmlSchemaForm::Unqualified, IsNullable=false)]
UInt32 m_ID;
[XmlElement(DataType="unsignedInt", ElementName=S"Size", Namespace=S"",
Form=Schema::XmlSchemaForm::Unqualified, IsNullable=false)]
UInt32 m_Size;
[XmlElement(DataType="string", ElementName=S"Signature", Namespace=S"",
Form=Schema::XmlSchemaForm::Unqualified, IsNullable=false)]
String* m_Signature;
[XmlElement(DataType = S"base64Binary", ElementName=S"Data", Namespace=S"",
Form=Schema::XmlSchemaForm::Unqualified, IsNullable=false)]
Byte m_Data[];
/// OTHER THINGS I HAVE TRIED:
//[XmlArrayAttribute(Form=Schema::XmlSchemaForm::Unqu alified)]
//[XmlArrayItemAttribute(ElementName=S"Data",Form=Sch ema::XmlSchemaForm::Unqualified,
IsNullable=false)]
//char* m_Data;
//[XmlArray(ElementName=S"Data", DataType="base64Binary",
Form=Schema::XmlSchemaForm::Unqualified)]
//[XmlArrayItemAttribute(ElementName=S"Data",Form=Sch ema::XmlSchemaForm::Unqualified,
IsNullable=false)]
// [XmlArrayItemAttribute(__typeof(Byte[]), DataType="hexBinary",
ElementName=S"Data",Form=Schema::XmlSchemaForm::Un qualified,
IsNullable=false)]
// Byte m_Data __gc[];
// END OF TRIED THINGS
[XmlElement(__typeof(MMib),ElementName=S"MIB",Names pace=S"",Form=Schema::XmlSchemaForm::Unqualified,I sNullable=false)]
MMib* m_Mib;
};
Thanks for the Help!
Aug 17 '06 #1
0 1412

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Wayne Wengert | last post by:
Using VB.NET I want to read in an XML file that has an array of objects and then step through the resulting array in code. I build a class to define the structure and I am running code to read in...
2
by: Andrew G. J. Fung | last post by:
Can anyone please explain to me why the code below throws an exception? It seems to occur when deserializing an instance of a subclass, whose base class holds a struct, where said struct holds an...
2
by: Earl Teigrob | last post by:
I am saving and restoring value types such as Int32, DateTime and Boolean in strings. I was wondering if there is a mechanism build into .NET for serializing and deserializing these to string...
5
by: Daniel Gackle | last post by:
I'm getting a strange ArgumentNullException after deserializing a SortedList. Haven't seen this discussed in the newsgroups, but it looks like a bug - unless I missed something obvious? I've...
6
by: Steve Teeples | last post by:
I use serialization to write class data to a file. During my development of this class I need to add properties or fields on occation. After adding a property, when deserializing the data saved...
2
by: ce | last post by:
Being a newbie regarding serialization and memorystreams, I was trying to see if i could improve page performance (avoiding going to the db on a postback) by saving my serialized business object in...
0
by: Chris Newby | last post by:
Given: public class MyClass{ public String MyPropertyOne; } I have a soap document created by serializing an instance of a previous version of MyClass. However, now MyClass looks like: ...
4
by: georges the man | last post by:
hey guys, i ve been posting for the last week trying to understand some stuff about c and reading but unfortunaly i couldnt do this. i have to write the following code. this will be the last...
1
by: shapper | last post by:
Hello, Consider I have a String: Dim MyString As String = "Hello" or an Integer: Dim MyInteger As Integer = 100
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.