本文整理汇总了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();
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}