當前位置: 首頁>>代碼示例>>C#>>正文


C# BinarySerializer.BeginChunk方法代碼示例

本文整理匯總了C#中BinarySerializer.BeginChunk方法的典型用法代碼示例。如果您正苦於以下問題:C# BinarySerializer.BeginChunk方法的具體用法?C# BinarySerializer.BeginChunk怎麽用?C# BinarySerializer.BeginChunk使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BinarySerializer的用法示例。


在下文中一共展示了BinarySerializer.BeginChunk方法的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.BeginChunk方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。