public unsafe void WriteBatchSpaced( int numValues, ReadOnlySpan <short> defLevels, ReadOnlySpan <short> repLevels, ReadOnlySpan <byte> validBits, long validBitsOffset, ReadOnlySpan <TValue> values) { if (values == null) { throw new ArgumentNullException(nameof(values)); } if (defLevels == null) { throw new ArgumentNullException(nameof(defLevels)); } if (repLevels == null) { throw new ArgumentNullException(nameof(repLevels)); } if (validBits == null) { throw new ArgumentNullException(nameof(validBits)); } //if (values.Length < numValues) throw new ArgumentOutOfRangeException("numValues is larger than length of values"); if (defLevels.Length < numValues) { throw new ArgumentOutOfRangeException(nameof(defLevels), "numValues is larger than length of defLevels"); } if (repLevels.Length < numValues) { throw new ArgumentOutOfRangeException(nameof(repLevels), "numValues is larger than length of repLevels"); } // https://stackoverflow.com/questions/17944/how-to-round-up-the-result-of-integer-division if (validBits.Length < (validBitsOffset + numValues + 7) / 8) { throw new ArgumentOutOfRangeException(nameof(validBits), "numValues is larger than the bit length of validBits"); } var type = typeof(TValue); fixed(short *pDefLevels = defLevels) fixed(short *pRepLevels = repLevels) fixed(byte *pValidBits = validBits) fixed(TValue * pValues = values) { if (type == typeof(bool)) { ExceptionInfo.Check(TypedColumnWriter_WriteBatchSpaced_Bool(Handle, numValues, pDefLevels, pRepLevels, pValidBits, validBitsOffset, (bool *)pValues)); return; } if (type == typeof(int)) { ExceptionInfo.Check(TypedColumnWriter_WriteBatchSpaced_Int32(Handle, numValues, pDefLevels, pRepLevels, pValidBits, validBitsOffset, (int *)pValues)); return; } if (type == typeof(long)) { ExceptionInfo.Check(TypedColumnWriter_WriteBatchSpaced_Int64(Handle, numValues, pDefLevels, pRepLevels, pValidBits, validBitsOffset, (long *)pValues)); return; } if (type == typeof(Int96)) { ExceptionInfo.Check(TypedColumnWriter_WriteBatchSpaced_Int96(Handle, numValues, pDefLevels, pRepLevels, pValidBits, validBitsOffset, (Int96 *)pValues)); return; } if (type == typeof(float)) { ExceptionInfo.Check(TypedColumnWriter_WriteBatchSpaced_Float(Handle, numValues, pDefLevels, pRepLevels, pValidBits, validBitsOffset, (float *)pValues)); return; } if (type == typeof(double)) { ExceptionInfo.Check(TypedColumnWriter_WriteBatchSpaced_Double(Handle, numValues, pDefLevels, pRepLevels, pValidBits, validBitsOffset, (double *)pValues)); return; } if (type == typeof(ByteArray)) { ExceptionInfo.Check(TypedColumnWriter_WriteBatchSpaced_ByteArray(Handle, numValues, pDefLevels, pRepLevels, pValidBits, validBitsOffset, (ByteArray *)pValues)); return; } if (type == typeof(FixedLenByteArray)) { ExceptionInfo.Check(TypedColumnWriter_WriteBatchSpaced_FixedLenByteArray(Handle, numValues, pDefLevels, pRepLevels, pValidBits, validBitsOffset, (FixedLenByteArray *)pValues)); return; } throw new NotSupportedException($"type {type} is not supported"); } }
public unsafe void WriteBatch(int numValues, ReadOnlySpan <short> defLevels, ReadOnlySpan <short> repLevels, ReadOnlySpan <TValue> values) { if (values == null) { throw new ArgumentNullException(nameof(values)); } if (defLevels != null && defLevels.Length < numValues) { throw new ArgumentOutOfRangeException(nameof(defLevels), "numValues is larger than length of defLevels"); } if (repLevels != null && repLevels.Length < numValues) { throw new ArgumentOutOfRangeException(nameof(repLevels), "numValues is larger than length of repLevels"); } var type = typeof(TValue); fixed(short *pDefLevels = defLevels) fixed(short *pRepLevels = repLevels) fixed(TValue * pValues = values) { if (type == typeof(bool)) { ExceptionInfo.Check(TypedColumnWriter_WriteBatch_Bool(Handle, numValues, pDefLevels, pRepLevels, (bool *)pValues)); return; } if (type == typeof(int)) { ExceptionInfo.Check(TypedColumnWriter_WriteBatch_Int32(Handle, numValues, pDefLevels, pRepLevels, (int *)pValues)); return; } if (type == typeof(long)) { ExceptionInfo.Check(TypedColumnWriter_WriteBatch_Int64(Handle, numValues, pDefLevels, pRepLevels, (long *)pValues)); return; } if (type == typeof(Int96)) { ExceptionInfo.Check(TypedColumnWriter_WriteBatch_Int96(Handle, numValues, pDefLevels, pRepLevels, (Int96 *)pValues)); return; } if (type == typeof(float)) { ExceptionInfo.Check(TypedColumnWriter_WriteBatch_Float(Handle, numValues, pDefLevels, pRepLevels, (float *)pValues)); return; } if (type == typeof(double)) { ExceptionInfo.Check(TypedColumnWriter_WriteBatch_Double(Handle, numValues, pDefLevels, pRepLevels, (double *)pValues)); return; } if (type == typeof(ByteArray)) { ExceptionInfo.Check(TypedColumnWriter_WriteBatch_ByteArray(Handle, numValues, pDefLevels, pRepLevels, (ByteArray *)pValues)); return; } if (type == typeof(FixedLenByteArray)) { ExceptionInfo.Check(TypedColumnWriter_WriteBatch_FixedLenByteArray(Handle, numValues, pDefLevels, pRepLevels, (FixedLenByteArray *)pValues)); return; } throw new NotSupportedException($"type {type} is not supported"); } }