当前位置: 首页>>代码示例>>C#>>正文


C# BinarySerializer.EndChunk方法代码示例

本文整理汇总了C#中BinarySerializer.EndChunk方法的典型用法代码示例。如果您正苦于以下问题:C# BinarySerializer.EndChunk方法的具体用法?C# BinarySerializer.EndChunk怎么用?C# BinarySerializer.EndChunk使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinarySerializer的用法示例。


在下文中一共展示了BinarySerializer.EndChunk方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1:

        /// <inheritdoc/>
        void IDataSerializable.Serialize(BinarySerializer serializer)
        {
            // Starts the whole EffectData by the magiccode "TKFX"
            // If the serializer don't find the TKFX, It will throw an
            // exception that will be catched by Load method.
            serializer.BeginChunk(MagicCode);

            // Shaders section
            serializer.BeginChunk("SHDR");
            serializer.Serialize(ref Shaders);
            serializer.EndChunk();

            // Effects section
            serializer.BeginChunk("EFFX");
            serializer.Serialize(ref Effects);
            serializer.EndChunk();

            // Close TKFX section
            serializer.EndChunk();
        }
开发者ID:rbwhitaker,项目名称:SharpDX,代码行数:21,代码来源:EffectData.cs

示例2:

        /// <inheritdoc/>
        void IDataSerializable.Serialize(BinarySerializer serializer)
        {
            // Starts the whole ModelData by the magiccode "TKMD"
            // If the serializer don't find the TKMD, It will throw an
            // exception that will be catched by Load method.
            serializer.BeginChunk(MagicCode);

            // Bones section
            serializer.BeginChunk("BONE");
            serializer.Serialize(ref Bones);
            serializer.EndChunk();

            // Mesh section
            serializer.BeginChunk("MESH");
            serializer.Serialize(ref Meshes);
            serializer.EndChunk();

            // Serialize attributes
            serializer.Serialize(ref Attributes);

            // Close TKFX section
            serializer.EndChunk();
        }
开发者ID:rbwhitaker,项目名称:SharpDX,代码行数:24,代码来源:ModelData.cs

示例3: SaveTKTX

        /// <summary>
        /// Saves the specified pixel buffers in TKTX format.
        /// </summary>
        /// <param name="pixelBuffers">The pixel buffers.</param>
        /// <param name="count">The count.</param>
        /// <param name="description">The description.</param>
        /// <param name="imageStream">The image stream.</param>
        internal static void SaveTKTX(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream)
        {
            var serializer = new BinarySerializer(imageStream, SerializerMode.Write);

            var beginPosition = imageStream.Position;

            // Write MagicCode for TKTX
            serializer.BeginChunk(MagicCodeTKTX);

            // Serialize Description
            serializer.Serialize(ref description);

            // Serialize Size
            int size = 0;
            for (int i = 0; i < count; i++)
                size += pixelBuffers[i].BufferStride;
            serializer.Serialize(ref size);

            // Pad to align pixel buffer on 16 bytes (fixed offset at 48 bytes from the beginning of the file).
            var padBuffer = new byte[OffsetBufferTKTX - (int) (imageStream.Position - beginPosition)];
            if (padBuffer.Length > 0)
                imageStream.Write(padBuffer, 0, padBuffer.Length);

            // Write the whole pixel buffer
            for (int i = 0; i < count; i++)
                serializer.SerializeMemoryRegion(pixelBuffers[i].DataPointer, pixelBuffers[i].BufferStride);

            serializer.EndChunk();
        }
开发者ID:rbwhitaker,项目名称:SharpDX,代码行数:36,代码来源:Image.cs

示例4: LoadTKTX

        /// <summary>
        /// Saves the specified pixel buffers in TKTX format.
        /// </summary>
        internal static Image LoadTKTX(IntPtr dataPointer, int dataSize, bool makeACopy, GCHandle? handle)
        {
            // Make a copy?
            if (makeACopy)
            {
                var temp = Utilities.AllocateMemory(dataSize);
                Utilities.CopyMemory(temp, dataPointer, dataSize);
                dataPointer = temp;
            }

            // Use DataStream to load from memory pointer
            var imageStream = new DataStream(dataPointer, dataSize, true, true);

            var beginPosition = imageStream.Position;

            var serializer = new BinarySerializer(imageStream, SerializerMode.Read);
            var description = default(ImageDescription);

            // Load MagicCode TKTX
            try
            {
                serializer.BeginChunk(MagicCodeTKTX);
            } catch (InvalidChunkException ex)
            {
                // If magic code not found, return null
                if (ex.ExpectedChunkId == MagicCodeTKTX)
                    return null;
                throw;
            }

            // Read description
            serializer.Serialize(ref description);

            // Read size of pixel buffer
            int size = 0;
            serializer.Serialize(ref size);

            // Pad to align pixel buffer on 16 bytes (fixed offset at 48 bytes from the beginning of the file).
            var padBuffer = new byte[OffsetBufferTKTX - (int)(imageStream.Position - beginPosition)];
            if (padBuffer.Length > 0)
            {
                if (imageStream.Read(padBuffer, 0, padBuffer.Length) != padBuffer.Length)
                    throw new EndOfStreamException();
            }

            // Check that current offset is exactly our fixed offset.
            int pixelBufferOffsets = (int)serializer.Stream.Position;
            if (pixelBufferOffsets != OffsetBufferTKTX)
                throw new InvalidOperationException(string.Format("Unexpected offset [{0}] for pixel buffers. Must be {1}", pixelBufferOffsets, OffsetBufferTKTX));

            // Seek to the end of the stream to the number of pixel buffers
            imageStream.Seek(size, SeekOrigin.Current);

            // Close the chunk to verify that we did read the whole chunk
            serializer.EndChunk();

            return new Image(description, dataPointer, pixelBufferOffsets, handle, makeACopy);
        }
开发者ID:rbwhitaker,项目名称:SharpDX,代码行数:61,代码来源:Image.cs

示例5: NotSupportedException

        /// <inheritdoc/>
        void IDataSerializable.Serialize(BinarySerializer serializer)
        {
            // Starts the whole EffectData by the magiccode "TKFX"
            // If the serializer don't find the TKFX, It will throw an
            // exception that will be catched by Load method.
            serializer.BeginChunk(MagicCode);

            // Writes the version
            if (serializer.Mode == SerializerMode.Read)
            {
                int version = serializer.Reader.ReadInt32();
                if (version != Version)
                {
                    throw new NotSupportedException(string.Format("EffectData version [0x{0:X}] is not supported. Expecting [0x{1:X}]", version, Version));
                }
            }
            else
            {
                serializer.Writer.Write(Version);
            }

            // Shaders section
            serializer.BeginChunk("SHDR");
            serializer.Serialize(ref Shaders);
            serializer.EndChunk();

            // Effects section
            serializer.BeginChunk("EFFX");
            serializer.Serialize(ref Description);
            serializer.EndChunk();

            // Close TKFX section
            serializer.EndChunk();
        }
开发者ID:s33m3,项目名称:SharpDX,代码行数:35,代码来源:EffectData.cs

示例6: NotSupportedException

        /// <inheritdoc/>
        void IDataSerializable.Serialize(BinarySerializer serializer)
        {
            // Starts the whole ModelData by the magiccode "TKMD"
            // If the serializer don't find the TKMD, It will throw an
            // exception that will be catched by Load method.

            // This code should not be modified without modifying the serialize code in Model.

            serializer.BeginChunk(MagicCode);

            // Writes the version
            if (serializer.Mode == SerializerMode.Read)
            {
                int version = serializer.Reader.ReadInt32();
                if (version != Version)
                {
                    throw new NotSupportedException(string.Format("ModelData version [0x{0:X}] is not supported. Expecting [0x{1:X}]", version, Version));
                }
            }
            else
            {
                serializer.Writer.Write(Version);
            }

            // Serialize the maximum buffer size used when loading this model.
            serializer.Serialize(ref MaximumBufferSizeInBytes);

            // Texture section
            serializer.BeginChunk("TEXS");
            if (serializer.Mode == SerializerMode.Read)
            {
                int textureCount = serializer.Reader.ReadInt32();
                Textures = new List<byte[]>(textureCount);
                for (int i = 0; i < textureCount; i++)
                {
                    byte[] textureData = null;
                    serializer.Serialize(ref textureData);
                    Textures.Add(textureData);
                }
            }
            else
            {
                serializer.Writer.Write(Textures.Count);
                for (int i = 0; i < Textures.Count; i++)
                {
                    byte[] textureData = Textures[i];
                    serializer.Serialize(ref textureData);
                }
            }
            serializer.EndChunk();

            // Material section
            serializer.BeginChunk("MATL");
            serializer.Serialize(ref Materials);
            serializer.EndChunk();

            // Bones section
            serializer.BeginChunk("BONE");
            serializer.Serialize(ref Bones);
            serializer.EndChunk();

            //// DISABLE_SKINNED_BONES
            //// Skinned Bones section
            //serializer.BeginChunk("SKIN");
            //serializer.Serialize(ref SkinnedBones);
            //serializer.EndChunk();

            // Mesh section
            serializer.BeginChunk("MESH");
            serializer.Serialize(ref Meshes);
            serializer.EndChunk();

            // Serialize attributes
            serializer.Serialize(ref Attributes);

            // Close TKMD section
            serializer.EndChunk();
        }
开发者ID:Ziriax,项目名称:SharpDX,代码行数:79,代码来源:ModelData.cs


注:本文中的BinarySerializer.EndChunk方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。