Example #1
0
        public void CacheFlatBuffersData(string name, string version, System.ArraySegment <byte> buffer)
        {
            FlatBuffersDataCache cache = new FlatBuffersDataCache();

            cache.Version = version;
            cache.Buffer  = buffer;
            Cache(name, cache);
        }
Example #2
0
        public void RegisterFlatBuffersEntity(string name, OnFlatBuffersDataCacheUpdated onupdated)
        {
            if (EntityRegistered(name))
            {
                return;
            }

            RegisterEntity <FlatBuffersDataCache>(name, delegate(string dname, IVersionedDataCache dcache)
            {
                FlatBuffersDataCache buffer = dcache as FlatBuffersDataCache;
                if (onupdated != null)
                {
                    onupdated(dname, buffer.Buffer);
                }
            });
        }
Example #3
0
        public void Serialize(Stream stream, IVersionedDataCache data_cache_obj)
        {
            FlatBuffersDataCache data = data_cache_obj as FlatBuffersDataCache;

            using (BinaryWriter bw = new BinaryWriter(stream))
            {
                byte[] version = EB.Encoding.GetBytes(data.Version);
                if (version.Length != VERSION_OFFSET)
                {
                    EB.Debug.LogWarning("FlatBufferTableDataCacheSerializer.Serialize: resize invalid version {0}", data.Version);

                    byte[] buffer = new byte[VERSION_OFFSET];
                    System.Buffer.BlockCopy(version, 0, buffer, 0, System.Math.Min(version.Length, VERSION_OFFSET));
                    version = buffer;
                }

                bw.Write(version);
                bw.Write(data.Buffer.Array, data.Buffer.Offset, data.Buffer.Count);
            }
        }
Example #4
0
        public IVersionedDataCache Deserialize(Stream stream)
        {
            FlatBuffersDataCache data = new FlatBuffersDataCache();

            using (BinaryReader br = new BinaryReader(stream))
            {
                byte[] version = br.ReadBytes(VERSION_OFFSET);
                data.Version = EB.Encoding.GetString(version).TrimEnd(new char[] { (char)0 });

                using (var ms = new MemoryStream())
                {
                    byte[] buffer = new byte[512];
                    int    count  = 0;
                    while ((count = br.Read(buffer, 0, buffer.Length)) != 0)
                    {
                        ms.Write(buffer, 0, count);
                    }
                    data.Buffer = new System.ArraySegment <byte>(ms.GetBuffer(), 0, (int)ms.Position);
                }
            }
            return(data);
        }