Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/Vibrant.InfluxDB.Client/Helpers/BigIntConversionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Numerics;

namespace Vibrant.InfluxDB.Client.Helpers
{
internal static class BigIntConversionHelper
{
public static object ChangeType(BigInteger value, Type conversionType)
{
if (conversionType == null)
{
throw new ArgumentNullException(nameof(conversionType));
}

switch (Type.GetTypeCode(conversionType))
{
case TypeCode.Boolean:
return value == 1;

case TypeCode.Char:
return (char)value;

case TypeCode.SByte:
return (sbyte)value;

case TypeCode.Byte:
return (byte)value;

case TypeCode.Int16:
return (short)value;

case TypeCode.UInt16:
return (ushort)value;

case TypeCode.Int32:
return (int)value;

case TypeCode.UInt32:
return (uint)value;

case TypeCode.Int64:
return (long)value;

case TypeCode.UInt64:
return (ulong)value;

case TypeCode.Single:
return (float)value;

case TypeCode.Double:
return (double)value;

case TypeCode.Decimal:
return (decimal)value;

case TypeCode.String:
return value.ToString();

default:
throw new NotSupportedException($"Not supported data type: {conversionType}");
}
}
}
}
6 changes: 6 additions & 0 deletions src/Vibrant.InfluxDB.Client/Parsers/ResultSetFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
using Vibrant.InfluxDB.Client.Rows;
using Vibrant.InfluxDB.Client.Http;
using System.Collections.Concurrent;
using System.Numerics;
using System.Threading;
using Vibrant.InfluxDB.Client.Helpers;

namespace Vibrant.InfluxDB.Client.Parsers
{
Expand Down Expand Up @@ -196,6 +198,10 @@ private static void AddValuesToInfluxSeriesByAttributes<TInfluxRow, TTimestamp>(
property.SetValue( dataPoint, Convert.ChangeType( stringValue, property.Type, CultureInfo.InvariantCulture ) );
}
}
else if (value is BigInteger bigIntValue)
{
property.SetValue(dataPoint, BigIntConversionHelper.ChangeType(bigIntValue, property.Type));
}
else
{
property.SetValue( dataPoint, Convert.ChangeType( value, property.Type, CultureInfo.InvariantCulture ) );
Expand Down