public void TestEncodeDecode()
        {
            var fileInfo = new CacheFileInfo
            {
                Crc              = -893872,
                Version          = 1598632487,
                CompressedSize   = 2389,
                UncompressedSize = 9238,
                Entries          = new Dictionary <int, CacheFileEntryInfo>()
            };

            fileInfo.Entries[0] = new CacheFileEntryInfo();
            fileInfo.Entries[5] = new CacheFileEntryInfo();

            var referenceTable = new ReferenceTableFile
            {
                Options = ReferenceTableOptions.Sizes,
            };

            referenceTable.SetFileInfo(3, fileInfo);

            var encodedReferenceTable = referenceTable.Encode();
            var decodedReferenceTable = ReferenceTableFile.Decode(encodedReferenceTable);
            var decodedFileInfo       = decodedReferenceTable.GetFileInfo(3);

            Assert.Equal(fileInfo.Crc, decodedFileInfo.Crc);
            Assert.Equal(fileInfo.Version, decodedFileInfo.Version);
            Assert.Equal(fileInfo.CompressedSize, decodedFileInfo.CompressedSize);
            Assert.Equal(fileInfo.UncompressedSize, decodedFileInfo.UncompressedSize);
            Assert.Equal(fileInfo.Entries.Keys, decodedFileInfo.Entries.Keys);
        }
        public void TestDecodeEncodeFromCache(CacheIndex index)
        {
            var referenceTableFile = this._fixture.JavaClientCache.GetFile(CacheIndex.ReferenceTables, (int)index);
            var referenceTable     = ReferenceTableFile.Decode(referenceTableFile.Data);

            var encodedFile = referenceTable.Encode();

            Assert.True(referenceTableFile.Data.SequenceEqual(encodedFile));
        }
Пример #3
0
        public ReferenceTableFile GetReferenceTable(CacheIndex index, bool createIfNotFound = false)
        {
            // Obtain the reference table either from our own cache or the actual cache
            if (this._cachedReferenceTables.ContainsKey(index))
            {
                return(this._cachedReferenceTables[index]);
            }

            return(this._cachedReferenceTables.GetOrAdd(index, _ =>
            {
                try
                {
                    var file = this.GetFile(CacheIndex.ReferenceTables, (int)index);
                    return ReferenceTableFile.Decode(file.Data);
                }
                catch (CacheFileNotFoundException) when(createIfNotFound)
                {
                    return new ReferenceTableFile
                    {
                        Options = ReferenceTableOptions.Sizes,
                    };
                }
            }));
        }
Пример #4
0
        public void TestGetReferenceTableFile(Type cacheType, CacheIndex index)
        {
            var cache = this._fixture.Caches[cacheType];

            ReferenceTableFile.Decode(cache.GetFile(CacheIndex.ReferenceTables, (int)index).Data);
        }