Skip to content

Commit a51ea77

Browse files
authored
fix: added supports for unsigned numbers (#150)
1 parent 0272fa3 commit a51ea77

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Bug Fixes
44
1. [#143](https://github.com/influxdata/influxdb-client-csharp/pull/143): Added validation that a configuration is present when is client configured via file
5+
1. [#150](https://github.com/influxdata/influxdb-client-csharp/pull/150): The unsigned numbers are serialized with `u` postfix
56

67
### Dependencies
78
1. [#145](https://github.com/influxdata/influxdb-client-csharp/pull/145): Updated RestSharp to 106.11.7

Client.Test/ItWriteApiAsyncTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,27 @@ await _writeApi.WriteMeasurementsAsync(_bucket.Name, _organization.Name, WritePr
156156
Assert.AreEqual(Instant.FromDateTimeUtc(dtDateTime.AddSeconds(ii)), record.GetTime());
157157
}
158158
}
159+
160+
[Test]
161+
public async Task WriteULongValues()
162+
{
163+
Client.SetLogLevel(LogLevel.Body);
164+
var pointData = PointData.Measurement("h2o")
165+
.Tag("location", "coyote_creek")
166+
.Field("max_ulong", ulong.MaxValue)
167+
.Timestamp(9L, WritePrecision.S);
168+
169+
await _writeApi.WritePointAsync(pointData);
170+
171+
List<FluxTable> query = await Client.GetQueryApi().QueryAsync(
172+
"from(bucket:\"" + _bucket.Name +
173+
"\") |> range(start: 1970-01-01T00:00:00.000000001Z)",
174+
_organization.Id);
175+
176+
Assert.AreEqual(1, query.Count);
177+
Assert.AreEqual(1, query[0].Records.Count);
178+
179+
Assert.AreEqual(ulong.MaxValue, query[0].Records[0].GetValue());
180+
}
159181
}
160182
}

Client.Test/PointDataTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void FieldTypes()
147147

148148
var expected =
149149
"h2o,location=europe boolean=false,byte=9i,decimal=25.6,double=250.69,float=35,integer=7i,long=1i," +
150-
"point=13.3,sbyte=12i,short=8i,string=\"string value\",uint=11i,ulong=10i,ushort=13i";
150+
"point=13.3,sbyte=12i,short=8i,string=\"string value\",uint=11u,ulong=10u,ushort=13u";
151151

152152
Assert.AreEqual(expected, point.ToLineProtocol());
153153
}
@@ -416,5 +416,7 @@ public void OnlyInfinityValues()
416416

417417
Assert.AreEqual("", point.ToLineProtocol());
418418
}
419+
420+
419421
}
420422
}

Client/Writes/PointData.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ public PointData Tag(string name, string value)
9494
_fields);
9595
}
9696

97+
/// <summary>
98+
/// Add a field with a <see cref="byte"/> value.
99+
/// </summary>
100+
/// <param name="name">the field name</param>
101+
/// <param name="value">the field value</param>
102+
/// <returns>this</returns>
103+
public PointData Field(string name, byte value)
104+
{
105+
return PutField(name, value);
106+
}
107+
97108
/// <summary>
98109
/// Add a field with a <see cref="float"/> value.
99110
/// </summary>
@@ -149,6 +160,17 @@ public PointData Field(string name, ulong value)
149160
return PutField(name, value);
150161
}
151162

163+
/// <summary>
164+
/// Add a field with a <see cref="uint"/> value.
165+
/// </summary>
166+
/// <param name="name">the field name</param>
167+
/// <param name="value">the field value</param>
168+
/// <returns>this</returns>
169+
public PointData Field(string name, uint value)
170+
{
171+
return PutField(name, value);
172+
}
173+
152174
/// <summary>
153175
/// Add a field with a <see cref="string"/> value.
154176
/// </summary>
@@ -410,12 +432,16 @@ private bool AppendFields(StringBuilder sb)
410432

411433
if (value is double || value is float)
412434
{
413-
sb.Append(((IConvertible)value).ToString(CultureInfo.InvariantCulture));
435+
sb.Append(((IConvertible) value).ToString(CultureInfo.InvariantCulture));
436+
}
437+
else if (value is uint || value is ulong || value is ushort)
438+
{
439+
sb.Append(((IConvertible) value).ToString(CultureInfo.InvariantCulture));
440+
sb.Append('u');
414441
}
415-
else if (value is byte || value is int || value is long || value is sbyte || value is short ||
416-
value is uint || value is ulong || value is ushort)
442+
else if (value is byte || value is int || value is long || value is sbyte || value is short)
417443
{
418-
sb.Append(((IConvertible)value).ToString(CultureInfo.InvariantCulture));
444+
sb.Append(((IConvertible) value).ToString(CultureInfo.InvariantCulture));
419445
sb.Append('i');
420446
}
421447
else if (value is bool b)

0 commit comments

Comments
 (0)