Пример #1
0
        public void TestReadStructArray()
        {
            var item1 =
                new CachedFileHeaderStruct
            {
                lenPath = 1
            };
            var serializer = new StructSerializer <CachedFileHeaderStruct>();

            byte[] bytes = serializer.ToByteArray(item1);
            Assert.AreEqual(Marshal.SizeOf <CachedFileHeaderStruct>(), bytes.Length);
            var roundTrip = serializer.FromByteArray(bytes);

            Assert.AreEqual(item1, roundTrip);
        }
Пример #2
0
        public void TestShorterSizeOnDisk()
        {
            var item1 = new CachedFileHeaderStruct
            {
                modified          = 1,
                lenInstrumentInfo = 100,
            };
            var serializer = new StructSerializer <CachedFileHeaderStruct>()
            {
                ItemSizeOnDisk = 8
            };

            byte[] bytes = serializer.ResizeByteArray(serializer.ToByteArray(item1), 8);
            Assert.AreEqual(8, bytes.Length);
            var roundTrip = serializer.FromByteArray(bytes);

            Assert.AreEqual(1, roundTrip.modified);
            Assert.AreEqual(0, roundTrip.lenInstrumentInfo);
        }