Ejemplo n.º 1
0
        public BBDataCache(ByteBuffer buffer, int id)
        {
            Checker.Assert(buffer != null && id != 0);

            _bBData = new BBData <T>(buffer.id, id);

            _buffer         = buffer;
            _version        = buffer.version;
            _headerPtrCache = buffer.FindHeaderPtrWithID(id);
            _dataPtrCache   = buffer.GetData <T>(_headerPtrCache);
        }
Ejemplo n.º 2
0
        internal BBDataCache(ByteBuffer buffer, BBDataHeader *headerPtr, T *dataPtr)
        {
            Checker.Assert(buffer != null && buffer.isValid && headerPtr != null && dataPtr != null);

            _bBData = new BBData <T>(buffer.id, headerPtr->id);

            _buffer         = buffer;
            _version        = buffer.version;
            _headerPtrCache = headerPtr;
            _dataPtrCache   = dataPtr;
        }
Ejemplo n.º 3
0
        private void CheckVersion()
        {
            if (_buffer == null)
            {
                _buffer = ByteBuffer.Get(_bBData.bbId);
            }
            else if (_version == _buffer.version)
            {
                return;
            }

            Checker.Assert(isValid);
            //版本发生变化,重新缓存指针
            _headerPtrCache = _buffer.FindHeaderPtrWithID(_bBData.id);
            _dataPtrCache   = _buffer.GetData <T>(_headerPtrCache);
            _version        = _buffer.version;
        }
Ejemplo n.º 4
0
        private static void Init()
        {
            SuperLog.Log("TypeManager 初始化");

            _types = new HashSet <Type>();

            var assemblies = AppDomain.CurrentDomain.GetAssemblies();

            foreach (var assembly in assemblies)
            {
                var assemblyTypes = assembly.GetTypes();

                foreach (var type in assemblyTypes)
                {
                    if (!typeof(IByteBufferData).IsAssignableFrom(type) || !UnsafeUtility.IsUnmanaged(type))
                    {
                        continue;
                    }

                    _types.Add(type);
                }
            }

            _id2Type = new Dictionary <int, Type>(_types.Count);
            _type2id = new Dictionary <Type, int>(_types.Count);
            _id2size = new Dictionary <int, int>(_types.Count);

            foreach (var type in _types)
            {
                int id = Hash128.Compute(type.FullName).GetHashCode();
                Checker.Assert(id != 0);
                _id2Type.Add(id, type);
                _type2id.Add(type, id);
                _id2size.Add(id, UnsafeUtility.SizeOf(type));
            }
        }
Ejemplo n.º 5
0
 public BBData(int bbId, int id)
 {
     Checker.Assert(bbId != 0 && id != 0);
     this.bbId = bbId;
     this.id   = id;
 }