Example #1
0
        public static List <T> Merge <T>(List <T> to,
                                         List <T> patch) where T : class, IPatchClass <T>, new()
        {
            var count     = patch.Count;
            var lastCount = to.Count;

            to = FieldSerializeUtil.Resize(to, count);
            for (int i = 0; i < count; i++)
            {
                if (patch[i].HasValue)
                {
                    PatchPropertySerializer.MergeFromPatch(to[i], patch[i]);
                }
            }

            return(to);
        }
Example #2
0
        /// <summary>
        /// size是不会变的,否则重新生成
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dest"></param>
        /// <param name="origin"></param>
        /// <returns></returns>
        public static T[] Merge <T>(T[] dest,
                                    T[] origin) where T : class, IPatchClass <T>, new()
        {
            var oc = origin.Length;
            var dc = dest.Length;

            dest = FieldSerializeUtil.Resize(dest, oc);
            for (int i = 0; i < oc; i++)
            {
                if (origin[i].HasValue)
                {
//                    dest[i].MergeFromPatch(origin[i]);
                    PatchPropertySerializer.MergeFromPatch(dest[i], origin[i]);
                }
            }

            return(dest);
        }
        public static void Serialize <T>(List <T> list, Core.Utils.MyBinaryWriter writer, List <T> lastList = null,
                                         bool writeAll = false) where T : IPatchClass <T>, new()
        {
            BitArrayWrapper bitArray  = GetDiffBitArray(lastList, list, writeAll);
            var             count     = list == null ? 0 : list.Count;
            var             lastCount = lastList == null ? 0 : lastList.Count;

            writer.Write(bitArray);

            for (int i = 0; i < count; i++)
            {
                if (bitArray[i] == false)
                {
                    continue;
                }
                var last = i >= lastCount || writeAll ? default(T) : lastList[i];
                PatchPropertySerializer.Write(list[i], last, writer);
            }

            bitArray.ReleaseReference();
        }
 private static T Deserialize <T>(T last, BinaryReader reader) where T : class, IPatchClass <T>, new()
 {
     PatchPropertySerializer.Read(last, reader);
     return(last);
 }
 private static void Serialize <T>(T curr, T last, MyBinaryWriter writer) where T : class, IPatchClass <T>, new()
 {
     PatchPropertySerializer.Write(curr, last, writer);
 }