Skip to content

Commit

Permalink
Fixed exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Dec 4, 2024
1 parent 7545283 commit ea22d63
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/DotNext/Buffers/ByteBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static int WriteLittleEndian<T>(this IBufferWriter<byte> writer, T value)
for (var destination = writer.GetSpan(); !value.TryWriteLittleEndian(destination, out length); destination = writer.GetSpan(length))
{
length = destination.Length;
length = length <= MaxBufferSize ? length << 1 : throw new InsufficientMemoryException();
length = length <= MaxBufferSize ? length << 1 : throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory);
}

writer.Advance(length);
Expand All @@ -64,7 +64,7 @@ public static int WriteBigEndian<T>(this IBufferWriter<byte> writer, T value)
for (var destination = writer.GetSpan(); !value.TryWriteBigEndian(destination, out length); destination = writer.GetSpan(length))
{
length = destination.Length;
length = length <= MaxBufferSize ? length << 1 : throw new InsufficientMemoryException();
length = length <= MaxBufferSize ? length << 1 : throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory);
}

writer.Advance(length);
Expand All @@ -84,7 +84,7 @@ public static int Write(this IBufferWriter<byte> writer, in BigInteger value, bo
{
var buffer = writer.GetSpan(value.GetByteCount(isUnsigned));
if (!value.TryWriteBytes(buffer, out var bytesWritten, isUnsigned, isBigEndian))
throw new InsufficientMemoryException();
throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory);

writer.Advance(bytesWritten);
return bytesWritten;
Expand All @@ -108,7 +108,7 @@ public static int Format<T>(this IBufferWriter<byte> writer, T value, ReadOnlySp
for (int sizeHint; !value.TryFormat(buffer, out bytesWritten, format, provider); buffer = writer.GetSpan(sizeHint))
{
sizeHint = buffer.Length;
sizeHint = sizeHint <= MaxBufferSize ? sizeHint << 1 : throw new InsufficientMemoryException();
sizeHint = sizeHint <= MaxBufferSize ? sizeHint << 1 : throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory);
}

writer.Advance(bytesWritten);
Expand Down Expand Up @@ -143,7 +143,7 @@ public static int WriteLittleEndian<T>(this ref BufferWriterSlim<byte> writer, T
for (var destination = writer.InternalGetSpan(sizeHint: 0); !value.TryWriteLittleEndian(destination, out length); destination = writer.InternalGetSpan(length))
{
length = destination.Length;
length = length <= MaxBufferSize ? length << 1 : throw new InsufficientMemoryException();
length = length <= MaxBufferSize ? length << 1 : throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory);
}

writer.Advance(length);
Expand All @@ -165,7 +165,7 @@ public static int WriteBigEndian<T>(this ref BufferWriterSlim<byte> writer, T va
for (var destination = writer.InternalGetSpan(sizeHint: 0); !value.TryWriteBigEndian(destination, out length); destination = writer.InternalGetSpan(length))
{
length = destination.Length;
length = length <= MaxBufferSize ? length << 1 : throw new InsufficientMemoryException();
length = length <= MaxBufferSize ? length << 1 : throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory);
}

writer.Advance(length);
Expand All @@ -185,7 +185,7 @@ public static int Write(this ref BufferWriterSlim<byte> writer, in BigInteger va
{
var buffer = writer.InternalGetSpan(value.GetByteCount(isUnsigned));
if (!value.TryWriteBytes(buffer, out var bytesWritten, isUnsigned, isBigEndian))
throw new InsufficientMemoryException();
throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory);

writer.Advance(bytesWritten);
return bytesWritten;
Expand All @@ -209,7 +209,7 @@ public static int Format<T>(this ref BufferWriterSlim<byte> writer, T value, Rea
for (int sizeHint; !value.TryFormat(buffer, out bytesWritten, format, provider); buffer = writer.InternalGetSpan(sizeHint))
{
sizeHint = buffer.Length;
sizeHint = sizeHint <= MaxBufferSize ? sizeHint << 1 : throw new InsufficientMemoryException();
sizeHint = sizeHint <= MaxBufferSize ? sizeHint << 1 : throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory);
}

writer.Advance(bytesWritten);
Expand Down Expand Up @@ -258,7 +258,7 @@ public static int WriteLittleEndian<T>(this ref SpanWriter<byte> writer, T value
where T : notnull, IBinaryInteger<T>
{
if (!value.TryWriteLittleEndian(writer.RemainingSpan, out var bytesWritten))
throw new InsufficientMemoryException();
throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory);

writer.Advance(bytesWritten);
return bytesWritten;
Expand All @@ -276,7 +276,7 @@ public static int WriteBigEndian<T>(this ref SpanWriter<byte> writer, T value)
where T : notnull, IBinaryInteger<T>
{
if (!value.TryWriteBigEndian(writer.RemainingSpan, out var bytesWritten))
throw new InsufficientMemoryException();
throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory);

writer.Advance(bytesWritten);
return bytesWritten;
Expand Down
4 changes: 2 additions & 2 deletions src/DotNext/Buffers/CharBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static int Format(this IBufferWriter<char> writer, CompositeFormat format
const int maxBufferSize = int.MaxValue / 2;

int bufferSize;
for (bufferSize = 0; ; bufferSize = bufferSize <= maxBufferSize ? bufferSize << 1 : throw new InsufficientMemoryException())
for (bufferSize = 0; ; bufferSize = bufferSize <= maxBufferSize ? bufferSize << 1 : throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory))
{
var buffer = writer.GetSpan(bufferSize);
if (buffer.TryWrite(provider, format, out bufferSize, args))
Expand Down Expand Up @@ -203,7 +203,7 @@ public static int Format(this ref BufferWriterSlim<char> writer, CompositeFormat
const int maxBufferSize = int.MaxValue / 2;

int bufferSize;
for (bufferSize = 0; ; bufferSize = bufferSize <= maxBufferSize ? bufferSize << 1 : throw new InsufficientMemoryException())
for (bufferSize = 0; ; bufferSize = bufferSize <= maxBufferSize ? bufferSize << 1 : throw new InsufficientMemoryException(ExceptionMessages.NotEnoughMemory))
{
var buffer = writer.InternalGetSpan(bufferSize);
if (buffer.TryWrite(provider, format, out bufferSize, args))
Expand Down

0 comments on commit ea22d63

Please sign in to comment.