public void Visit(uint tag, string name, bool require, ref IStruct val) { if (val == null) { return; } if (require) { PackHead(tag, SdpPackDataType.SdpPackDataType_StructBegin); val.Visit(this); PackHead(0u, SdpPackDataType.SdpPackDataType_StructEnd); } else { SdpWriter sdp = new SdpWriter(); sdp.PackHead(tag, SdpPackDataType.SdpPackDataType_StructBegin); uint iStartPos = sdp.CurrPos(); val.Visit(sdp); if (iStartPos < sdp.CurrPos()) { sdp.PackHead(0u, SdpPackDataType.SdpPackDataType_StructEnd); WriteRawByte(sdp.ToBytes()); } } }
public static byte[] Serializer <T>(this T val) { SdpWriter writer = new SdpWriter(); writer.Pack(val); return(writer.ToBytes()); }
public void Write(object value, SdpWriter writer, uint tag, bool require) { if (value != null) { IStruct t = (IStruct)value; writer.Visit(tag, null, require, ref t); } }
public static bool Serializer <T>(this T val, MemoryStream memst) { SdpWriter writer = new SdpWriter(memst); var ser = GetSerializer <T>(); if (ser != null) { ser.Write(val, writer, 0, true); return(true); } else { Type type = typeof(T); if (type.IsEnum) { writer.VisitEunm(0, null, true, ref val); return(true); } else { foreach (var it in type.GetInterfaces()) { if (it == typeof(IDictionary)) { Type[] genericTypes = type.GetGenericArguments(); IDictionary dir = (IDictionary)val; var keySer = GetSerializer(genericTypes[0]); var valSer = GetSerializer(genericTypes[1]); writer.Visit(0, null, true, ref dir, keySer, genericTypes[0], valSer, genericTypes[1]); return(true); } else if (it == typeof(IList)) { Type[] genericTypes = type.GetGenericArguments(); IList list = (IList)val; var serT = GetSerializer(genericTypes[0]); writer.Visit(0, null, true, ref list, serT, genericTypes[0]); return(true); } } } } return(false); }
public static bool Serializer <T>(this T val, MemoryStream memst) { SdpWriter writer = new SdpWriter(memst); return(writer.Pack(val, 0)); }
public void Write(object value, SdpWriter writer, uint tag, bool require) { ulong iValue = (ulong)value; writer.Visit(tag, null, require, ref iValue); }
public void Write(object value, SdpWriter writer, uint tag, bool require) { byte[] str = (byte[])value; writer.Visit(tag, null, require, ref str); }
public void Write(object value, SdpWriter writer, uint tag, bool require) { string str = ((Guid)value).ToString(); writer.Visit(tag, null, require, ref str); }
public void Write(object value, SdpWriter writer, uint tag, bool require) { int val = (int)value; writer.Visit(tag, null, require, ref val); }
public void Write(object value, SdpWriter writer, uint tag, bool require) { string str = (string)value; writer.Visit(tag, null, require, ref str); }
public void Write(object value, SdpWriter writer, uint tag, bool require) { DateTime time = (DateTime)value; writer.Visit(tag, null, require, ref time); }
public void Write(object value, SdpWriter writer, uint tag, bool require) { bool bValue = (bool)value; writer.Visit(tag, null, require, ref bValue); }
public void Write(object value, SdpWriter writer, uint tag, bool require) { double fValue = (double)value; writer.Visit(tag, null, require, ref fValue); }