public void TestShaderParametersSerialization()
        {
            // Test serialization
            var shaderParameters = new ShaderMixinParameters("Test");
            shaderParameters.Set(PropertyInt, 5);
            var subShaderParameters = new ShaderMixinParameters("Sub");
            subShaderParameters.Set(PropertyInt, 6);
            shaderParameters.Set(PropertySub, subShaderParameters);

            var subShaderParametersArray = new ShaderMixinParameters[1];
            var subShaderParametersArray1 = new ShaderMixinParameters("InArray1");
            subShaderParametersArray[0] = subShaderParametersArray1;
            subShaderParametersArray1.Set(PropertyInt, 7);
            shaderParameters.Set(PropertySubs, subShaderParametersArray);

            var memoryStream = new MemoryStream();
            var writer = new BinarySerializationWriter(memoryStream);
            writer.Write(shaderParameters);
            writer.Flush();
            memoryStream.Position = 0;

            var reader = new BinarySerializationReader(memoryStream);
            var shaderParametersReloaded = reader.Read<ShaderMixinParameters>();

            // They should be strictly equal
            Assert.That(shaderParametersReloaded.IsSubsetOf(shaderParameters), Is.True);
            Assert.That(shaderParameters.IsSubsetOf(shaderParametersReloaded), Is.True);

            // Test subset
            // Check that by removing one key from the original parameters, the reloaded version is
            // no longer a subset
            subShaderParametersArray1.Remove(PropertyInt);
            Assert.That(shaderParametersReloaded.IsSubsetOf(shaderParameters), Is.False);
        }
Beispiel #2
0
        /// <summary>
        /// Reads an object instance from the specified byte buffer.
        /// </summary>
        /// <typeparam name="T">Type of the object to read</typeparam>
        /// <param name="buffer">The byte buffer to read the object instance.</param>
        /// <returns>An object instance of type T.</returns>
        public static T Read <T>([NotNull] byte[] buffer)
        {
            var reader = new BinarySerializationReader(new MemoryStream(buffer));

            return(reader.Read <T>());
        }
Beispiel #3
0
 /// <summary>
 /// Loads an <see cref="EffectBytecode" /> from a stream.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <returns>EffectBytecode or null if the magic header is not matching</returns>
 /// <exception cref="System.ArgumentNullException">stream</exception>
 public static EffectBytecode FromStream(Stream stream)
 {
     if (stream == null) throw new ArgumentNullException("stream");
     var reader = new BinarySerializationReader(stream);
     var version = reader.Read<uint>();
     // Version is not matching, return null
     if (version != MagicHeader)
     {
         return null;
     }
     return reader.Read<EffectBytecode>();
 }
Beispiel #4
0
        /// <summary>
        /// Reads an object instance from the specified stream.
        /// </summary>
        /// <typeparam name="T">Type of the object to read</typeparam>
        /// <param name="stream">The stream to read the object instance.</param>
        /// <returns>An object instance of type T.</returns>
        public static T Read <T>([NotNull] Stream stream)
        {
            var reader = new BinarySerializationReader(stream);

            return(reader.Read <T>());
        }