private byte[] GetBytes(byte[] data, ref int startIndex, int bytesToRead)
{
// if input data is null
if (null == data)
{
throw new FormatException(ConstValue.ERROR_MESSAGE_DATA_NULL_REF);
}
// if index is out of range
if ((startIndex < 0) || (startIndex + bytesToRead > data.Length))
{
throw new FormatException(ConstValue.ERROR_MESSAGE_DATA_INDEX_OUT_OF_RANGE);
}
// read bytes of specific length
byte[] dataRead = new byte[bytesToRead];
Array.Copy(data, startIndex, dataRead, 0, bytesToRead);
// update index
startIndex += bytesToRead;
return dataRead;
}