private void SaveBlockDataToBuffer(ref byte[] DataBuffer, ref UInt32 cur_pos, byte[] pBlockData, UInt32 PageSize = 512) { UInt32 BlockDataSize = (UInt32)pBlockData.Length; if (PageSize < BlockDataSize) PageSize = BlockDataSize; stBlockHeader CurBlockHeader = new stBlockHeader(); CurBlockHeader.EOL_0D = 0xd; CurBlockHeader.EOL_0A = 0xa; CurBlockHeader.EOL2_0D = 0xd; CurBlockHeader.EOL2_0A = 0xa; CurBlockHeader.data_size_hex = _intTo_BytesChar(BlockDataSize); CurBlockHeader.page_size_hex = _intTo_BytesChar(PageSize); CurBlockHeader.next_page_addr_hex = _intTo_BytesChar(0x7fffffff); CurBlockHeader.space1 = 0x20; CurBlockHeader.space2 = 0x20; CurBlockHeader.space3 = 0x20; Array.Copy(CurBlockHeader.ToBytes(), 0, DataBuffer, cur_pos, stBlockHeader.Size()); cur_pos += stBlockHeader.Size(); Array.Copy(pBlockData, 0, DataBuffer, cur_pos, BlockDataSize); cur_pos += BlockDataSize; for (UInt32 i = 0; i < PageSize - BlockDataSize; i++) { DataBuffer[cur_pos] = 0; cur_pos++; } }
private void SaveBlockDataToBuffer(ref BinaryWriter DataBufferStream, MemoryTributary pBlockDataStream, UInt32 PageSize = 512) { UInt32 BlockDataSize = (UInt32)pBlockDataStream.Length; if (PageSize < BlockDataSize) PageSize = BlockDataSize; stBlockHeader CurBlockHeader = new stBlockHeader(); CurBlockHeader.EOL_0D = 0xd; CurBlockHeader.EOL_0A = 0xa; CurBlockHeader.EOL2_0D = 0xd; CurBlockHeader.EOL2_0A = 0xa; CurBlockHeader.data_size_hex = _intTo_BytesChar(BlockDataSize); CurBlockHeader.page_size_hex = _intTo_BytesChar(PageSize); CurBlockHeader.next_page_addr_hex = _intTo_BytesChar(0x7fffffff); CurBlockHeader.space1 = 0x20; CurBlockHeader.space2 = 0x20; CurBlockHeader.space3 = 0x20; DataBufferStream.BaseStream.Position = 0; DataBufferStream.Write(CurBlockHeader.ToBytes()); pBlockDataStream.Position = 0; for (int i = 0; i < pBlockDataStream.Length; i++) { DataBufferStream.Write(Convert.ToByte(pBlockDataStream.ReadByte())); } DataBufferStream.BaseStream.SetLength(DataBufferStream.BaseStream.Length + (PageSize - BlockDataSize)); }