public void TestStructure() { for (int i = 1; i <= RepeatCnt; i++) { Console.WriteLine(">>> Iteration started: " + i); // 1. Generate and shuffle objects. IList<BranchedType> objs = new List<BranchedType>(); for (int j = 0; j < 6 * ObjectsPerMode; j++) objs.Add(new BranchedType((j%6) + 1)); objs = IgniteUtils.Shuffle(objs); // 2. Create new marshaller. BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(typeof(BranchedType)); BinaryConfiguration cfg = new BinaryConfiguration { TypeConfigurations = new List<BinaryTypeConfiguration> { typeCfg } }; Marshaller marsh = new Marshaller(cfg); // 3. Marshal all data and ensure deserialized object is fine. // Use single stream to test object offsets using (var stream = new BinaryHeapStream(128)) { var writer = marsh.StartMarshal(stream); foreach (var obj in objs) { Console.WriteLine(">>> Write object [mode=" + obj.mode + ']'); writer.WriteObject(obj); } stream.Seek(0, SeekOrigin.Begin); var reader = marsh.StartUnmarshal(stream); foreach (var obj in objs) { var other = reader.ReadObject<BranchedType>(); Assert.IsTrue(obj.Equals(other)); } } Console.WriteLine(); // 4. Ensure that all fields are recorded. var desc = marsh.GetDescriptor(typeof (BranchedType)); CollectionAssert.AreEquivalent(new[] {"mode", "f2", "f3", "f4", "f5", "f6", "f7", "f8"}, desc.WriterTypeStructure.FieldTypes.Keys); } }
/// <summary> /// Copying constructor. /// </summary> /// <param name="cfg">Configuration to copy.</param> public BinaryTypeConfiguration(BinaryTypeConfiguration cfg) { AffinityKeyFieldName = cfg.AffinityKeyFieldName; IdMapper = cfg.IdMapper; NameMapper = cfg.NameMapper; Serializer = cfg.Serializer; TypeName = cfg.TypeName; KeepDeserialized = cfg.KeepDeserialized; }
/// <summary> /// Copying constructor. /// </summary> /// <param name="cfg">Configuration to copy.</param> public BinaryTypeConfiguration(BinaryTypeConfiguration cfg) { IgniteArgumentCheck.NotNull(cfg, "cfg"); AffinityKeyFieldName = cfg.AffinityKeyFieldName; IdMapper = cfg.IdMapper; NameMapper = cfg.NameMapper; Serializer = cfg.Serializer; TypeName = cfg.TypeName; KeepDeserialized = cfg.KeepDeserialized; IsEnum = cfg.IsEnum; }
public void TestStructure() { for (int i = 1; i <= RepeatCnt; i++) { Console.WriteLine(">>> Iteration started: " + i); // 1. Generate and shuffle objects. IList<BranchedType> objs = new List<BranchedType>(); for (int j = 0; j < 6 * ObjectsPerMode; j++) objs.Add(new BranchedType((j%6) + 1)); objs = IgniteUtils.Shuffle(objs); // 2. Create new marshaller. BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(typeof(BranchedType)); BinaryConfiguration cfg = new BinaryConfiguration { TypeConfigurations = new List<BinaryTypeConfiguration> { typeCfg } }; Marshaller marsh = new Marshaller(cfg); // 3. Marshal all data and ensure deserialized object is fine. foreach (BranchedType obj in objs) { Console.WriteLine(">>> Write object [mode=" + obj.mode + ']'); byte[] data = marsh.Marshal(obj); BranchedType other = marsh.Unmarshal<BranchedType>(data); Assert.IsTrue(obj.Equals(other)); } Console.WriteLine(); // 4. Ensure that all fields are recorded. var desc = marsh.GetDescriptor(typeof (BranchedType)); CollectionAssert.AreEquivalent(new[] {"mode", "f2", "f3", "f4", "f5", "f6", "f7", "f8"}, desc.WriterTypeStructure.FieldTypes.Keys); } }