Example #1
0
        public bool TryGetValue0(K0 key0, out V value)
        {
            int idx = d0.Find(key0);

            if (idx == -1)
            {
                value = default(V);
                return(false);
            }
            value = d0.ValueAt(idx).value;
            return(true);
        }
Example #2
0
        public static void Register <T>(ushort typeId) where T : IObject, new()
        {
            var r = typeTypeIdMappings.Add(typeof(T), typeId);

            System.Diagnostics.Debug.Assert(r.success || typeTypeIdMappings.ValueAt(r.index) == typeId);
            TypeId <T> .value             = typeId;
            typeIdCreatorMappings[typeId] = () => { return(new T()); };
        }
Example #3
0
        public bool TryGetValue1(K1 key1, out V value)
        {
            int idx = d1.Find(key1);

            if (idx == -1)
            {
                value = default(V);
                return(false);
            }
            value = d1.ValueAt(idx).value;
            return(true);
        }
Example #4
0
        public void Read <T>(ref T v) where T : IObject
        {
            var typeId = (ushort)0;

            Read(ref typeId);
            if (typeId == 0)
            {
                v = default(T);
                return;
            }
            if (typeId == 1)
            {
                throw new Exception("Read<T> does not support string type");
            }
            if (idxStore != null)
            {
                uint ptr_offset = 0, bb_offset_bak = (uint)this.offset - (uint)offsetRoot;
                Read(ref ptr_offset);
                if (ptr_offset == bb_offset_bak)
                {
                    v = (T)CreateByTypeId(typeId);
                    System.Diagnostics.Debug.Assert(v != null);
                    idxStore.Add(ptr_offset, v);
                    v.FromBBuffer(this);
                }
                else
                {
                    int idx = idxStore.Find(ptr_offset);
                    if (idx == -1)
                    {
                        throw new Exception("ptr_offset is not found");
                    }
                    v = (T)idxStore.ValueAt(idx);
                    System.Diagnostics.Debug.Assert(v != null);
                }
            }
            else
            {
                v = (T)CreateByTypeId(typeId);
                System.Diagnostics.Debug.Assert(v != null);
                v.FromBBuffer(this);
            }
        }
Example #5
0
 public void Write <T>(T v) where T : IObject
 {
     if (v == null)
     {
         Write((ushort)0);
     }
     else
     {
         System.Diagnostics.Debug.Assert(v.GetPackageId() != ushort.MaxValue);   // 通常是没有执行 XXXPKG.AllTypes.Register() 所致
         Write(v.GetPackageId());
         if (ptrStore != null)
         {
             var rtv = ptrStore.Add(v, (uint)(dataLen - offsetRoot));        // 试将 v 和 相对offset 放入字典, 得到下标和是否成功
             Write(ptrStore.ValueAt(rtv.index));                             // 取 offset ( 不管是否成功 )
             if (!rtv.success)
             {
                 return;                                                     // 如果首次出现就序列化类本体
             }
         }
         v.ToBBuffer(this);
     }
 }