Ejemplo n.º 1
0
 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)));
     }
 }
Ejemplo n.º 2
0
        public void SdbDataHeadTest()
        {
            const FileFormatVersions FileFormat = FileFormatVersions.Office2010;
            var classIds                = new SdbClassIdToSchemaTypeIndex[5];
            var schemaTypes             = new SdbSchemaType[8];
            var particleConstraints     = new SdbParticleConstraint[2];
            var particleChildrenIndexes = new SdbParticleChildrenIndex[11];
            var attributes              = new SdbAttributeConstraint[4];

            var instance = new SdbDataHead(
                FileFormat,
                classIds,
                schemaTypes,
                particleConstraints,
                particleChildrenIndexes,
                attributes);

            Assert.Equal(FileFormat, instance.FileFormat);

            Assert.Equal(SdbSpan.Create(instance.ClassIds.Offset, classIds), instance.ClassIds);
            Assert.Equal(instance.ClassIds.End, instance.SchemaType.Offset);

            Assert.Equal(SdbSpan.Create(instance.SchemaType.Offset, schemaTypes), instance.SchemaType);
            Assert.Equal(instance.SchemaType.End, instance.Particles.Offset);

            Assert.Equal(SdbSpan.Create(instance.Particles.Offset, particleConstraints), instance.Particles);
            Assert.Equal(instance.Particles.End, instance.ParticleChildren.Offset);

            Assert.Equal(SdbSpan.Create(instance.ParticleChildren.Offset, particleChildrenIndexes), instance.ParticleChildren);
            Assert.Equal(instance.ParticleChildren.End, instance.Attributes.Offset);

            Assert.Equal(SdbSpan.Create(instance.Attributes.Offset, attributes), instance.Attributes);
            Assert.Equal(instance.Attributes.End, instance.End);

            var expected = new byte[]
            {
                0xB7, 0x55, 0xDD, 0x06, 0x4D, 0xEF, 0xEE, 0x46, 0xA6, 0x18, 0x04, 0x2A, 0xF4,
                0xC3, 0x90, 0x4E, 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x05, 0x00,
                0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
                0x00, 0x08, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
                0x0D, 0x00, 0x00, 0x00, 0xBE, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x02,
                0x00, 0x00, 0x00, 0xD4, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00,
                0x00, 0x00,
            };

            var bytes = VerifyBytes(instance, expected);

            var deserialized = Assert.Single(Deserialize <SdbDataHead>(bytes));

            Assert.Equal(instance, deserialized);
        }
Ejemplo n.º 3
0
 public SdbDataHead(
     FileFormatVersions fileFormat,
     SdbClassIdToSchemaTypeIndex[] classIdMap,
     SdbSchemaType[] schemaTypes,
     SdbParticleConstraint[] particles,
     SdbParticleChildrenIndex[] particleIndexes,
     SdbAttributeConstraint[] attributes)
 {
     Version          = CurrentVersion;
     FileFormat       = fileFormat;
     ClassIds         = SdbSpan.Create(Marshal.SizeOf <SdbDataHead>(), classIdMap);
     SchemaType       = SdbSpan.Create(ClassIds.End, schemaTypes);
     Particles        = SdbSpan.Create(SchemaType.End, particles);
     ParticleChildren = SdbSpan.Create(Particles.End, particleIndexes);
     Attributes       = SdbSpan.Create(ParticleChildren.End, attributes);
 }