-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from CirclesUBI/feature/circles-get-trust-rela…
…tions Don't serialize numbers as hex when returning a DatabaseQueryResult from rpc
- Loading branch information
Showing
8 changed files
with
147 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,67 @@ | ||
using System.Numerics; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Circles.Index.Common; | ||
|
||
public record DatabaseQueryResult(string[] Columns, IEnumerable<object[]> Rows); | ||
[JsonConverter(typeof(DatabaseQueryResultConverter))] | ||
public record DatabaseQueryResult( | ||
string[] Columns, | ||
IEnumerable<object[]> Rows); | ||
|
||
public class DatabaseQueryResultConverter : JsonConverter<DatabaseQueryResult> | ||
{ | ||
public override DatabaseQueryResult Read(ref Utf8JsonReader reader, Type typeToConvert, | ||
JsonSerializerOptions options) | ||
{ | ||
throw new NotImplementedException("Deserialization is not implemented."); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, DatabaseQueryResult value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStartObject(); | ||
|
||
writer.WritePropertyName("Columns"); | ||
JsonSerializer.Serialize(writer, value.Columns, options); | ||
|
||
writer.WritePropertyName("Rows"); | ||
writer.WriteStartArray(); | ||
foreach (var row in value.Rows) | ||
{ | ||
writer.WriteStartArray(); | ||
foreach (var item in row) | ||
{ | ||
switch (item) | ||
{ | ||
case int i: | ||
writer.WriteNumberValue(i); | ||
break; | ||
case long l: | ||
writer.WriteNumberValue(l); | ||
break; | ||
case float f: | ||
writer.WriteNumberValue(f); | ||
break; | ||
case double d: | ||
writer.WriteNumberValue(d); | ||
break; | ||
case decimal dec: | ||
writer.WriteNumberValue(dec); | ||
break; | ||
case BigInteger bigInt: | ||
writer.WriteStringValue(bigInt.ToString()); | ||
break; | ||
default: | ||
JsonSerializer.Serialize(writer, item, options); | ||
break; | ||
} | ||
} | ||
|
||
writer.WriteEndArray(); | ||
} | ||
|
||
writer.WriteEndArray(); | ||
|
||
writer.WriteEndObject(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters