I am reading data from a binary files with the purpose of converting it to xml. For this i have class with all the marshaling defined to read it.
The text values are as 32byte fixed length strings - in ANSI korean codepage.
I use XmlSerializer Serialize() to save it as xml.
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public byte[] pName;
However XmlSerializer only supports base64/hex with byte[].
I cannot use
UnmanagedType.ByValTStr
Because it does not allow specifying codepage and i get incorrect, corrupt strings like:
µðÆúÆ®º§¶óÅä³²ÀÚÀå°©1
How can i get the data to read as EUC-KR string or provide a custom serialization for these specific 32 byte arrays to convert it to readable format myself?
In total i am dealing with ~20 files, each with different structure - but usig same 32 byte strings for text.
So manual conversions and looping through nested data with various class structures is not a viable option.
UPDATE: example struct:
[StructLayout(LayoutKind.Sequential)]
public struct ClientData
{
[MarshalAs(UnmanagedType.U4)]
public uint index;
[MarshalAs(UnmanagedType.U4)]
public uint serial;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string pName;
public string StrName { get { return System.Text.Encoding.GetEncoding("EUC-KR").GetString(pName, 0, 32); } }
}
MarshalAshave to do with XML serialisation?public string strName { get { return Encoding.GetEncoding("EUC-KR").GetString(pName); } }, or do theGetStringmanually. The point is that you must have astringproperty for theXmlSerializerto save it as text.