Skip to content

Commit

Permalink
buffer util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rms80 committed May 11, 2018
1 parent 9f03660 commit c3cbf65
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions core/BufferUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,47 @@ static public IndexArray4i ToIndexArray4i(byte[] buffer)
}


/// <summary>
/// convert int array to bytes
/// </summary>
static public byte[] ToBytes(int[] array)
{
byte[] result = new byte[array.Length * sizeof(int)];
Buffer.BlockCopy(array, 0, result, 0, result.Length);
return result;
}

/// <summary>
/// convert short array to bytes
/// </summary>
static public byte[] ToBytes(short[] array)
{
byte[] result = new byte[array.Length * sizeof(short)];
Buffer.BlockCopy(array, 0, result, 0, result.Length);
return result;
}

/// <summary>
/// convert float array to bytes
/// </summary>
static public byte[] ToBytes(float[] array)
{
byte[] result = new byte[array.Length * sizeof(float)];
Buffer.BlockCopy(array, 0, result, 0, result.Length);
return result;
}

/// <summary>
/// convert double array to bytes
/// </summary>
static public byte[] ToBytes(double[] array)
{
byte[] result = new byte[array.Length * sizeof(double)];
Buffer.BlockCopy(array, 0, result, 0, result.Length);
return result;
}




/// <summary>
Expand Down

0 comments on commit c3cbf65

Please sign in to comment.