/// <summary> /// Creates an instance of <see cref="SdbSchemaData"/> using embedded streams for constraint data and simple types. /// </summary> /// <remarks> /// Constraint data are contained in a binary file that is defined as: /// /// <![CDATA[ /// [SdbDataHead][SdbClassIdToSchemaTypeIndex][SdbSchemaType][SdbParticleConstraint][SdbParticleChildrenIndex][SdbAttributeConstraint] /// ]]> /// /// Since the size of the arrays are different for different <paramref name="fileFormat"/>, these are all marshalled separately, with the information /// of offsets contained in <see cref="SdbDataHead"/>. These items are deserialized in this method, while <see cref="SerializeSdbData(Stream)"/> provides /// the infrastructure to serialize them back to a binary file in the correct order /// </remarks> /// <param name="fileFormat">The version to load</param> private SdbSchemaData(FileFormatVersions fileFormat) { if (!fileFormat.Any()) { throw new ArgumentOutOfRangeException(nameof(fileFormat)); } _fileFormat = fileFormat; using (var schema = GetStream(fileFormat, Constraints)) { var dataHead = SdbData.Deserialize <SdbDataHead>(schema); dataHead.Validate(); var length = (int)schema.Length; if (dataHead.End != length) { throw new InvalidDataException(); } ClassIdMap = SdbData.Deserialize <SdbClassIdToSchemaTypeIndex>(schema, dataHead.ClassIds); SchemaTypes = SdbData.Deserialize <SdbSchemaType>(schema, dataHead.SchemaType); Particles = SdbData.Deserialize <SdbParticleConstraint>(schema, dataHead.Particles); ParticleIndexes = SdbData.Deserialize <SdbParticleChildrenIndex>(schema, dataHead.ParticleChildren); Attributes = SdbData.Deserialize <SdbAttributeConstraint>(schema, dataHead.Attributes); } }
private static T[] Deserialize <T>(byte[] data) where T : struct { using (var ms = new MemoryStream(data)) { return(SdbData.Deserialize <T>(ms, SdbSpan.Create <T>(0))); } }