Skip to content

Commit

Permalink
Removed SafeMemoryMappedViewHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
mullerj committed Jul 19, 2024
1 parent 162a479 commit 35d70cf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 38 deletions.
20 changes: 3 additions & 17 deletions src/dotnet/tests/Mil.Navy.Nrl.Norm.IntegrationTests/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.IO.MemoryMappedFiles;
using System.Runtime.InteropServices;
using Mil.Navy.Nrl.Norm.Buffers;

Expand All @@ -9,29 +8,16 @@ namespace Mil.Navy.Nrl.Norm.IntegrationTests
/// </summary>
internal static class Extensions
{
/// <summary>
/// Obtain a byte buffer from a byte array buffer
/// </summary>
/// <param name="buffer">The byte array buffer</param>
/// <returns>The byte buffer based on the byte array</returns>
internal static ByteBuffer ToByteBuffer(this byte[] buffer)
{
var byteBuffer = ByteBuffer.AllocateDirect(buffer.Length);
byteBuffer.WriteArray(0, buffer, 0, buffer.Length);
return byteBuffer;
}

/// <summary>
/// Obtain a safe buffer from a byte array buffer
/// </summary>
/// <param name="buffer">The byte array buffer</param>
/// <returns>The safe buffer based on the byte array</returns>
internal static SafeBuffer ToSafeBuffer(this byte[] buffer)
{
using var memoryMappedFile = MemoryMappedFile.CreateNew(null, buffer.Length);
var memoryAccessor = memoryMappedFile.CreateViewAccessor(0, buffer.Length, MemoryMappedFileAccess.ReadWrite);
memoryAccessor.WriteArray(0, buffer, 0, buffer.Length);
return memoryAccessor.SafeMemoryMappedViewHandle;
var safeBuffer = ByteBuffer.AllocateDirect(buffer.Length);
safeBuffer.WriteArray(0, buffer, 0, buffer.Length);
return safeBuffer;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ public void EnqueuesData(string dataContent, string expectedDataContent, int dat
StartSender();
//Create data to write to enqueue
var data = Encoding.ASCII.GetBytes(dataContent);
using var dataBuffer = data.ToByteBuffer();
using var dataBuffer = data.ToSafeBuffer();
var expectedData = Encoding.ASCII.GetBytes(expectedDataContent);
//Create info to enqueue
var info = infoContent != null ? Encoding.ASCII.GetBytes(infoContent) : null;
Expand Down Expand Up @@ -552,7 +552,7 @@ public void EnqueuesDataThrowsExceptionWhenOutOfRange(string dataContent, int da
StartSender();
//Create data to enqueue
var data = Encoding.ASCII.GetBytes(dataContent);
using var dataBuffer = data.ToByteBuffer();
using var dataBuffer = data.ToSafeBuffer();
//Create info to enqueue
var info = infoContent != null ? Encoding.ASCII.GetBytes(infoContent) : null;

Expand Down Expand Up @@ -589,7 +589,7 @@ public void ReceivesData(string content, string expectedDataContent, int dataOff

//Create data to be sent
var data = Encoding.ASCII.GetBytes(content);
using var dataBuffer = data.ToByteBuffer();
using var dataBuffer = data.ToSafeBuffer();
var expectedData = Encoding.ASCII.GetBytes(expectedDataContent);
//Create info to be sent
var info = infoContent != null ? Encoding.ASCII.GetBytes(infoContent) : null;
Expand Down Expand Up @@ -1044,7 +1044,7 @@ public void RequeuesObject()
//Create data to write to the stream
var expectedContent = GenerateTextContent();
byte[] expectedData = Encoding.ASCII.GetBytes(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand Down Expand Up @@ -1083,7 +1083,7 @@ public void SetsWatermark()
//Create data to be sent
var expectedContent = GenerateTextContent();
var expectedData = Encoding.ASCII.GetBytes(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand Down Expand Up @@ -1132,7 +1132,7 @@ public void CancelsWatermark()
//Create data to be sent
var expectedContent = GenerateTextContent();
var expectedData = Encoding.ASCII.GetBytes(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand Down Expand Up @@ -1180,7 +1180,7 @@ public void ResetsWatermark()
//Create data to be sent
var expectedContent = GenerateTextContent();
var expectedData = Encoding.ASCII.GetBytes(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand Down Expand Up @@ -1251,7 +1251,7 @@ public void GetsAckingStatus()
//Create data to be sent
var expectedContent = GenerateTextContent();
var expectedData = Encoding.ASCII.GetBytes(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand Down Expand Up @@ -1686,7 +1686,7 @@ public void GetsObjectType_DATA()
//Create data to write to the stream
var expectedContent = GenerateTextContent();
byte[] expectedData = Encoding.ASCII.GetBytes(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand Down Expand Up @@ -1762,7 +1762,7 @@ public void GetsObjectSize()
var expectedContent = GenerateTextContent();
byte[] expectedData = Encoding.ASCII.GetBytes(expectedContent);
var expectedSize = Encoding.ASCII.GetByteCount(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand All @@ -1786,7 +1786,7 @@ public void SetsObjectNackingMode_NORM_NACK_NONE()
//Create data to write to the stream
var expectedContent = GenerateTextContent();
byte[] expectedData = Encoding.ASCII.GetBytes(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand All @@ -1810,7 +1810,7 @@ public void SetsObjectNackingMode_NORM_NACK_INFO_ONLY()
//Create data to write to the stream
var expectedContent = GenerateTextContent();
byte[] expectedData = Encoding.ASCII.GetBytes(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand All @@ -1834,7 +1834,7 @@ public void SetsObjectNackingMode_NORM_NACK_NORMAL()
//Create data to write to the stream
var expectedContent = GenerateTextContent();
byte[] expectedData = Encoding.ASCII.GetBytes(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand All @@ -1859,7 +1859,7 @@ public void GetsBytesPending()
var expectedContent = GenerateTextContent();
byte[] expectedData = Encoding.ASCII.GetBytes(expectedContent);
var expectedBytesPending = (long)0;
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand All @@ -1884,7 +1884,7 @@ public void CancelsObject()
//Create data to write to the stream
var expectedContent = GenerateTextContent();
byte[] expectedData = Encoding.ASCII.GetBytes(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand All @@ -1908,7 +1908,7 @@ public void RetainsObject()
//Create data to write to the stream
var expectedContent = GenerateTextContent();
byte[] expectedData = Encoding.ASCII.GetBytes(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand All @@ -1932,7 +1932,7 @@ public void ReleasesObject()
//Create data to write to the stream
var expectedContent = GenerateTextContent();
byte[] expectedData = Encoding.ASCII.GetBytes(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand All @@ -1957,7 +1957,7 @@ public void GetsSenderThrowsException()
//Create data to write to the stream
var expectedContent = GenerateTextContent();
byte[] expectedData = Encoding.ASCII.GetBytes(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand Down Expand Up @@ -1990,7 +1990,7 @@ public void GetsSender()
//Create data to be sent
var expectedContent = GenerateTextContent();
var expectedData = Encoding.ASCII.GetBytes(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand Down Expand Up @@ -2029,7 +2029,7 @@ public void GetsObjectHashCode()
//Create data to be sent
var expectedContent = GenerateTextContent();
var expectedData = Encoding.ASCII.GetBytes(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand Down Expand Up @@ -2070,7 +2070,7 @@ public void ObjectsEqual()
//Create data to be sent
var expectedContent = GenerateTextContent();
var expectedData = Encoding.ASCII.GetBytes(expectedContent);
using var dataBuffer = expectedData.ToByteBuffer();
using var dataBuffer = expectedData.ToSafeBuffer();

try
{
Expand Down

0 comments on commit 35d70cf

Please sign in to comment.