public static void UnsealedClassWithNoProperties()
 {
     FastestTreeSerialisationNotPossibleException(
         () => FastestTreeBinarySerialisation.EnsureThatTypeIsOptimalForFastestTreeSerialisation(typeof(ExampleOfUnsealedClassWithNoProperties), new IFastSerialisationTypeConverter[0]),
         typeof(ExampleOfUnsealedClassWithNoProperties),
         null
         );
 }
Пример #2
0
        public static void RoundTripOfStringTypeUsingFastSerialisation()
        {
            var value          = typeof(string);
            var typeConverters = new[] { TypeTypeConverter.Instance };
            var serialised     = FastestTreeBinarySerialisation.GetSerialiser(typeConverters).Serialise(value);
            var clone          = BinarySerialisation.Deserialise <Type>(serialised, typeConverters);

            Assert.Equal(value, clone);
        }
        public void Setup()
        {
            // The json files (and the object model) are derived from real world data that I deal with (it's not the entire object model - because I got bored exporting it and tidyig it up - but it's enough
            // to work with). All of the text and location values have been changed to maintain their length and spread of characters (ie. not all ASCII) but to ensure that it's all anonymous (it's public
            // data anyway but it does no harm to err on the safe side).
            _products = new DirectoryInfo("SampleData")
                        .EnumerateFiles("*.json")
                        .Select(file => JsonConvert.DeserializeObject <Product>(File.ReadAllText(file.FullName)))
                        .ToArray();

            // The EntitiesForFastestTreeBinarySerialisation classes are very similar to the regular entity classes but they have a few hints added that allow the SpeedyButLimited serialisation process to
            // apply more optimisations (see the ReadMe.txt file in the EntitiesForFastestTreeBinarySerialisation folder)
            _productsWithHintsForSpeedyButLimited = new DirectoryInfo("SampleData")
                                                    .EnumerateFiles("*.json")
                                                    .Select(file => JsonConvert.DeserializeObject <EntitiesForFastestTreeBinarySerialisation.Product>(File.ReadAllText(file.FullName)))
                                                    .ToArray();

            // Allow each library to "warm up" before any timings are taken - it could be argued that this work should be part of the benchmarks but I'm interested in how the serialisers compare in
            // performance when they're in use in a long-lived service and so I don't care about any warm up times
            // - Allow each library to serialise the data once
            _jsonNetSerialisedData         = JsonNetSerialise();
            _binaryFormatterSerialisedData = BinaryFormatterSerialise();
            RegisterTypesWithProtoBufThatShareAssemblyAndNamespaceWith(typeof(Product));             // Not putting protobuf-net attributes on the entities so let it do its reflection work as part of the warm up
            _protoBufSerialisedData      = ProtoBufSerialise();
            _danSerialiserSerialisedData = DanSerialiserSerialise();
            _danSerialiserSerialisedDataOptimisedForWideCircularReferences = DanSerialiserSerialise_OptimisedForWideCircularReferences();
            _fastestTreeBinarySerialisation                    = FastestTreeBinarySerialisation.GetSerialiser(new[] { DefaultEqualityComparerFastSerialisationTypeConverter.Instance });
            _danSerialiserSerialisedDataFastButSpeedy          = DanSerialiserSerialise_FastestTreeBinarySerialisation();
            _danSerialiserSerialisedDataFastButSpeedyWithHints = DanSerialiserSerialise_FastestTreeBinarySerialisationWithHints();
            // - Allow each library to deserialise the data once (apart from Json.NET, which has already deserialised the data to produce the _products and _productsOptimisedForSpeedyButLimited arrays)
            _warmUpDeserialisedProductsFromBinaryFormatter = BinaryFormatterDeserialise();
            _warmUpDeserialisedProductsFromProtoBuf        = ProtoBufDeserialise();
            _warmUpDeserialisedProductsFromDanSerialiser   = DanSerialiserDeserialise();
            _warmUpDeserialisedProductsFromDanSerialiserOptimisedForWideCircularReferences = DanSerialiserDeserialise_OptimisedForWideCircularReferences();
            _warmUpDeserialisedProductsFromDanSerialiserFastButSpeedy          = DanSerialiserDeserialise_FastestTreeBinarySerialisation();
            _warmUpDeserialisedProductsFromDanSerialiserFastButSpeedyWithHints = DanSerialiserDeserialise_FastestTreeBinarySerialisationWithHints();
        }
 public static void SealedClassWithNoPropertyThatIsArrayOfNullableEnum()
 {
     FastestTreeBinarySerialisation.EnsureThatTypeIsOptimalForFastestTreeSerialisation(typeof(ExampleOfSealedClassWithNullableEnumArrayProperty), new IFastSerialisationTypeConverter[0]);
 }
 public static void SealedClassWithNoProperties()
 {
     FastestTreeBinarySerialisation.EnsureThatTypeIsOptimalForFastestTreeSerialisation(typeof(ExampleOfSealedClassWithNoProperties), new IFastSerialisationTypeConverter[0]);
 }
 public static void String()
 {
     FastestTreeBinarySerialisation.EnsureThatTypeIsOptimalForFastestTreeSerialisation(typeof(string), new IFastSerialisationTypeConverter[0]);
 }