public object Read(SdpReader reader, uint tag, bool require, object value) { float val = 0f; reader.Visit(tag, null, require, ref val); return(val); }
public object Read(SdpReader reader, uint tag, bool require, object value) { IStruct t = value as IStruct; reader.Visit(tag, null, require, ref t); return(t); }
public object Read(SdpReader reader, uint tag, bool require, object value = null) { string val = Empty; reader.Visit(tag, null, require, ref val); return(new Guid(val)); }
public object Read(SdpReader reader, uint tag, bool require, object value = null) { int val = (int)value; reader.Visit(tag, null, require, ref val); return(val); }
public object Read(SdpReader reader, uint tag, bool require, object value) { DateTime time = Sdp.EpochOrigin; reader.Visit(tag, null, require, ref time); return(time); }
public static bool Deserialize <T>(this T val, byte[] data, int index = 0, int len = -1) { if (len == -1) { len = data.Length; } SdpReader reader = new SdpReader(data, (uint)index, (uint)len); return(reader.UnPack(ref val, 0)); }
public static bool Deserialize <T>(this T val, byte[] data) { SdpReader reader = new SdpReader(data, 0, 0); var ser = GetSerializer <T>(); if (val == null) { val = Activator.CreateInstance <T>(); } if (ser != null) { val = (T)ser.Read(reader, 0, true, val); return(true); } else { Type type = typeof(T); if (type.IsEnum) { reader.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]); reader.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]); reader.Visit(0, null, true, ref list, serT, genericTypes[0]); return(false); } } } } return(false); }
public static T Deserialize <T>(byte[] data, int index = 0, int len = -1) { if (len == -1) { len = data.Length; } T val = Activator.CreateInstance <T>(); SdpReader reader = new SdpReader(data, (uint)index, (uint)len); if (reader.UnPack(ref val, 0)) { return(val); } return(default(T)); }