Example #1
0
 public void Serialize(IO.EndianStream s, CondensedListInfo parentListInfo)
 {
     s.Stream(ref mIndex);
     if (Index != parentListInfo.DoneIndex)
     {
         s.Stream(ref Value);
     }
 }
Example #2
0
 public void Serialize(IO.EndianStream s, CondensedListInfo parentListInfo)
 {
     s.Stream(ref mIndex);
     if (Index != parentListInfo.DoneIndex)
     {
         if (s.IsReading)
         {
             Value = new T();
         }
         s.Stream(Value);
     }
 }
Example #3
0
        public static IO.EndianStream StreamList <T>(IO.EndianStream s, List <T> list,
                                                     CondensedListInfo info)
        // constraining it to struct instead of 'new()' generates less complex 'new T' code and avoids boxing ops
            where T : struct, ICondensedListItem
        {
            int capacity = list.Capacity;

            info.StreamCapacity(s, ref capacity);

            if (s.IsReading)
            {
                if (info.SerializeCapacity)
                {
                    Contract.Assert(capacity <= info.MaxCount);
                    list.Capacity = capacity;
                }

                var item = new T();
                for (item.Serialize(s, info); item.Index != info.DoneIndex; item.Serialize(s, info))
                {
                    Contract.Assert(list.Count <= info.MaxCount);
                    list.Add(item);
                }
            }
            else if (s.IsWriting)
            {
                foreach (var obj in list)
                {
                    obj.Serialize(s, info);
                }

                info.StreamDoneIndex(s);
            }

            return(s);
        }