Friday

binary serialize object c

here's sample of the object that could be serialized into string (binary not xml! ) and can be deserialized back.

it useful for creation protocols layer classes and here is example of
binary serializer
.
 
using System.Runtime.InteropServices;
using System.Text;
using CCLib.CCEngine.COMDATA;

namespace CCLib.CCEngine
{


namespace COMDATA
{
public class CApprovalCode
{
#region "Internal structures"

private SApprovalCode struc;

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct SApprovalCode
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
public char[] ApprovalCode;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public char[] RetrievalRefNumber;
}

public const int struc_size = 18;

#endregion

#region "Properties"

public string ApprovalCode
{
set { struc.ApprovalCode = BinFormatter.Set(value, 6); }
get { return new string(struc.ApprovalCode); }
}

public string RetrievalRefNumber
{
set { struc.RetrievalRefNumber = BinFormatter.Set(value, 12); }
get { return new string(struc.RetrievalRefNumber); }
}

#endregion

#region "Methods"

public CApprovalCode()
{
struc = new SApprovalCode();
struc.ApprovalCode = BinFormatter.Set("", 6);
struc.RetrievalRefNumber = BinFormatter.Set("", 12);
}

/// <summary>
/// Method for serializing structure into string
/// </summary>
public string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append(BinFormatter.RawSerializeStr(struc));

return sb.ToString();
}


/// <summary>
/// Method for de-serializing structure
/// </summary>
public void Parse(string s)
{
if (s != null && s != "")
{
struc = (SApprovalCode)BinFormatter.RawDeserializeStr(s.Substring(0, struc_size), struc.GetType());
}
}

#endregion
} //end CApprovalCode
}
}

No comments:

imagemagic add text to image

rem different types of text annotations on existing images rem cyan yellow orange gold rem -gravity SouthWest rem draw text and anno...