public static void MergeFrom(object obj, byte[] bytes, List <Object> objs) { if (bytes == null || bytes.Length == 0) { return; } var ts = GetByInstance(obj); if (ts == null) { return; } try { WRStream stream = new WRStream(bytes); stream.WritePos = bytes.Length; var ms = new MonoStream(stream, objs); ts.MergeFrom(ref obj, ms); } catch (System.Exception ex) { wxb.L.LogException(ex); } }
public static MonoStream WriteTo(object obj) { var stream = new MonoStream(512, new List <Object>()); BinarySerializable.GetByInstance(obj).WriteTo(obj, stream); return(stream); }
public static MonoStream WriteTo(object obj) { MonoStream ms = new MonoStream(new WRStream(512), new List <Object>()); GetByInstance(obj).WriteTo(obj, ms); return(ms); }
void ITypeSerialize.MergeFrom(ref object value, MonoStream ms) { int lenght = ms.Stream.ReadLength(); var array = value as Object[]; if (array == null || array.Length != lenght) { array = new Object[lenght]; value = array; } var stream = ms.Stream; for (int i = 0; i < lenght; ++i) { short pos = stream.ReadInt16(); if (pos == -1) { array[i] = null; } else { array[i] = ms.objs[pos]; } } }
void ITypeSerialize.WriteTo(object value, MonoStream ms) { if (value == null) { return; } ms.Stream.WriteInt16((short)ms.Add((Object)value)); }
public static void MergeFrom(object obj, byte[] bytes, List <Object> objs) { if (bytes == null) { return; } var ms = new MonoStream(bytes, objs); ms.WritePos = bytes.Length; BinarySerializable.MergeFrom(obj, ms); }
void ITypeSerialize.WriteTo(object value, MonoStream ms) { string[] array = value as string[]; if (array != null) { ms.Stream.WriteLength(array.Length); var stream = ms.Stream; for (int i = 0; i < array.Length; ++i) { stream.WriteString(array[i]); } } }
void ITypeSerialize.WriteTo(object value, MonoStream ms) { Object[] array = (Object[])value; if (array == null) { return; } ms.Stream.WriteLength(array.Length); var stream = ms.Stream; for (int i = 0; i < array.Length; ++i) { stream.WriteInt16((short)ms.Add(array[i])); } }
void ITypeSerialize.MergeFrom(ref object value, MonoStream ms) { int lenght = ms.Stream.ReadLength(); var array = value as IList <T>; if (array == null || array.Count != lenght) { array = Create(lenght); value = array; } var stream = ms.Stream; for (int i = 0; i < lenght; ++i) { array[i] = Read(stream); } }
void ITypeSerialize.MergeFrom(ref object value, MonoStream ms) { int lenght = ms.Stream.ReadLength(); var array = value as string[]; if (array == null || array.Length != lenght) { array = new string[lenght]; value = array; } var stream = ms.Stream; for (int i = 0; i < lenght; ++i) { array[i] = stream.ReadString(); } }
void ITypeSerialize.WriteTo(object value, MonoStream ms) { if (value == null) { return; } var stream = ms.Stream; ITypeSerialize ts = this; for (int i = 0; i < fieldInfos.Count; ++i) { var field = fieldInfos[i]; object cv = field.GetValue(value); if (cv == null) { continue; } ts = MonoSerialize.GetByType(field); stream.WriteString(field.Name); int count = ts.CalculateSize(cv); if (count == 0) { continue; } stream.WriteLength(count); #if UNITY_EDITOR int write_pos = stream.WritePos; #endif ts.WriteTo(cv, ms); #if UNITY_EDITOR if (stream.WritePos != write_pos + count) { UnityEngine.Debug.LogErrorFormat("type:{0} CalculateSize error!", ts.GetType().Name); } #endif } }
void ITypeSerialize.MergeFrom(ref object value, MonoStream ms) { var stream = ms.Stream; int lenght = stream.ReadLength(); var array = value as IList; if (array == null || array.Count != lenght) { array = Create(lenght); value = array; } for (int i = 0; i < lenght; ++i) { object v = array[i]; int count = stream.ReadLength(); if (count != 0) { int endpos = stream.WritePos; stream.WritePos = stream.ReadPos + count; try { elementTypeSerialize.MergeFrom(ref v, ms); array[i] = v; } catch (System.Exception ex) { wxb.L.LogException(ex); } finally { stream.WritePos = endpos; } } else { array[i] = null; } } }
void ITypeSerialize.WriteTo(object value, MonoStream ms) { IList <T> array = (IList <T>)value; if (array == null) { return; } int count = array.Count; ms.Stream.WriteLength(count); if (array != null) { var stream = ms.Stream; for (int i = 0; i < count; ++i) { Write(stream, array[i]); } } }
void ITypeSerialize.WriteTo(object value, MonoStream ms) { IList array = (IList)value; if (array == null) { return; } var stream = ms.Stream; stream.WriteLength(array.Count); for (int i = 0; i < array.Count; ++i) { int count = elementTypeSerialize.CalculateSize(array[i]); stream.WriteLength(count); if (count != 0) { elementTypeSerialize.WriteTo(array[i], ms); } } }
public void MergeFrom(ref object value, MonoStream ms) { if (value == null) { value = IL.Help.Create(type); } WRStream stream = ms.Stream; while (stream.ReadSize != 0) { var fieldName = stream.ReadString(); var length = stream.ReadLength(); if (length == 0) { } else { int endPos = stream.WritePos; stream.WritePos = stream.ReadPos + length; try { var fieldInfo = fieldInfos.Find((field) => { return(fieldName == field.Name); }); if (fieldInfo == null) { stream.ReadPos += length; } else { object cv = fieldInfo.GetValue(value); //bool isSet = false; //if (cv == null) //{ // cv = IL.Help.Create(fieldInfo.FieldType); // //isSet = true; //} MonoSerialize.GetByType(fieldInfo).MergeFrom(ref cv, ms); //if (isSet || !cv.GetType().IsClass || cv.GetType().FullName == "System.String") { fieldInfo.SetValue(value, cv); } } } catch (System.Exception ex) { UnityEngine.Debug.LogException(ex); } finally { #if UNITY_EDITOR if (stream.ReadSize != 0) { UnityEngine.Debug.LogErrorFormat("type:{0} fieldName:{1} length:{2}", type.Name, fieldName, length); } #endif stream.WritePos = endPos; } } } }
void ITypeSerialize.WriteTo(object obj, MonoStream ms) { T value = (T)obj; Write(ms.Stream, value); }
void ITypeSerialize.MergeFrom(ref object parent, MonoStream ms) { var pos = ms.Stream.ReadInt16(); parent = ms.objs[pos]; }
void ITypeSerialize.MergeFrom(ref object value, MonoStream ms) { value = Read(ms.Stream); }