public static object Parse(Chunk chunk, DataFormat fmt, int startOffset, out int readDataSize) { return Parse(chunk.ChunkBytes, fmt, startOffset, out readDataSize); }
public static object Parse(byte[] data, DataFormat fmt, int startOffset, out int readDataSize) { readDataSize = 0; // calculate data size int elemDataSize = fmt.ElementDataSize; long[] lengthArray = null; if (fmt.IsStaticSizedData) { lengthArray = fmt.LengthArray; } else { int lengthArraySize = 0; lengthArray = ReadLengthArray(data, startOffset, fmt.DimensionCount, out lengthArraySize); readDataSize += lengthArraySize; } // read data and generate object switch (fmt.Dimension) { case DataFormat.DataDimension.Scalar: { object v = ChunkReader.BigEndianBytesToObject(data, readDataSize + startOffset, fmt.DataType); readDataSize += elemDataSize; return v; } case DataFormat.DataDimension.Array1D: { object[] v = new object[lengthArray[0]]; for (int iElem = 0; iElem < lengthArray[0]; ++iElem) { v[iElem] = ChunkReader.BigEndianBytesToObject(data, readDataSize + startOffset, fmt.DataType); readDataSize += elemDataSize; } return v; } case DataFormat.DataDimension.Array2D: { object[,] v = new object[lengthArray[0], lengthArray[1]]; for (int yElem = 0; yElem < lengthArray[1]; ++yElem) { for (int xElem = 0; xElem < lengthArray[0]; ++xElem) { v[xElem, yElem] = ChunkReader.BigEndianBytesToObject(data, readDataSize + startOffset, fmt.DataType); readDataSize += elemDataSize; } } return v; } } return null; }
static public object Parse(Chunk chunk, DataFormat fmt, int startOffset, out int readDataSize) { return(Parse(chunk.ChunkBytes, fmt, startOffset, out readDataSize)); }