-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,093 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
|
||
*.cs text eol=crlf diff=csharp | ||
*.csproj text eol=crlf diff=csharp | ||
|
||
*.gz binary |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
namespace ExFat.Core.Buffers | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
public class Buffer | ||
{ | ||
private readonly int _offset; | ||
private readonly byte[] _bytes; | ||
|
||
/// <summary> | ||
/// Gets the length. | ||
/// </summary> | ||
/// <value> | ||
/// The length. | ||
/// </value> | ||
public int Length { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the <see cref="System.Byte"/> at the specified index. | ||
/// </summary> | ||
/// <value> | ||
/// The <see cref="System.Byte"/>. | ||
/// </value> | ||
/// <param name="index">The index.</param> | ||
/// <returns></returns> | ||
/// <exception cref="System.ArgumentOutOfRangeException"> | ||
/// index | ||
/// or | ||
/// index | ||
/// </exception> | ||
public byte this[int index] | ||
{ | ||
get | ||
{ | ||
if (index < 0 || index >= Length) | ||
throw new ArgumentOutOfRangeException(nameof(index)); | ||
return _bytes[_offset + index]; | ||
} | ||
set | ||
{ | ||
if (index < 0 || index >= Length) | ||
throw new ArgumentOutOfRangeException(nameof(index)); | ||
_bytes[_offset + index] = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the bytes. | ||
/// </summary> | ||
/// <returns></returns> | ||
public byte[] GetBytes() | ||
{ | ||
var bytes = new byte[Length]; | ||
Array.Copy(_bytes, _offset, bytes, 0, Length); | ||
return bytes; | ||
} | ||
|
||
public void Set(IList<byte> bytes) | ||
{ | ||
if (bytes.Count > Length) | ||
throw new ArgumentException(nameof(bytes)); | ||
for (int index = 0; index < bytes.Count; index++) | ||
_bytes[_offset + index] = bytes[index]; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Buffer"/> class given a raw array of bytes. | ||
/// </summary> | ||
/// <param name="bytes">The bytes.</param> | ||
public Buffer(byte[] bytes) | ||
{ | ||
_bytes = bytes; | ||
Length = _bytes.Length; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Buffer"/> class given another <see cref="Buffer"/>. | ||
/// </summary> | ||
/// <param name="buffer">The buffer.</param> | ||
/// <param name="offset">The offset.</param> | ||
/// <param name="length">The length.</param> | ||
/// <exception cref="System.ArgumentOutOfRangeException"> | ||
/// offset | ||
/// or | ||
/// length | ||
/// </exception> | ||
public Buffer(Buffer buffer, int offset, int length) | ||
{ | ||
if (offset < 0 || offset >= buffer.Length) | ||
throw new ArgumentOutOfRangeException(nameof(offset)); | ||
if (offset + length > buffer.Length) | ||
throw new ArgumentOutOfRangeException(nameof(length)); | ||
_bytes = buffer._bytes; | ||
_offset = buffer._offset + offset; | ||
Length = length; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Buffer"/> class given another <see cref="Buffer"/>. | ||
/// </summary> | ||
/// <param name="buffer">The buffer.</param> | ||
public Buffer(Buffer buffer) | ||
: this(buffer, 0, buffer.Length) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace ExFat.Core.Buffers | ||
{ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
[DebuggerDisplay("{" + nameof(Value) + "}")] | ||
public class BufferUInt16 : IValueProvider<UInt16> | ||
{ | ||
private readonly Buffer _buffer; | ||
|
||
/// <summary> | ||
/// Gets or sets the value. | ||
/// </summary> | ||
/// <value> | ||
/// The value. | ||
/// </value> | ||
public UInt16 Value | ||
{ | ||
get { return BitConverter.ToUInt16(_buffer.GetBytes().FromLittleEndian(), 0); } | ||
set { _buffer.Set(BitConverter.GetBytes(value).ToLittleEndian()); } | ||
} | ||
|
||
public BufferUInt16(Buffers.Buffer buffer, int offset) | ||
{ | ||
_buffer = new Buffers.Buffer(buffer, offset, sizeof(UInt16)); | ||
} | ||
} | ||
} |
Oops, something went wrong.