469,608 Members | 1,935 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,608 developers. It's quick & easy.

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 1220

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Wayne Wengert | last post: by
6 posts views Thread by Steve Teeples | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.