-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GrpcModels,Core: move Match converter
Move Match type converter from RedisStorageLayer to GrpcModels.ModelSerialization since it's not used in Redis, but only in GRPC.
- Loading branch information
1 parent
c2a9c8d
commit 5497e37
Showing
4 changed files
with
57 additions
and
45 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
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
namespace GrpcModels | ||
|
||
open System.Text.Json | ||
open System.Text.Json.Serialization | ||
|
||
open FsharpExchangeDotNetStandard | ||
|
||
module ModelSerialization = | ||
type MatchTypeConverter() = | ||
inherit JsonConverter<Match>() | ||
|
||
override this.Read(reader, _typeToConvert, _options) = | ||
if reader.TokenType <> JsonTokenType.StartObject then | ||
raise <| JsonException() | ||
|
||
// "Type" key | ||
reader.Read() |> ignore | ||
if reader.TokenType <> JsonTokenType.PropertyName || reader.GetString() <> "Type" then | ||
raise <| JsonException() | ||
// "Type" value | ||
reader.Read() |> ignore | ||
match reader.GetString() with | ||
| "Full" -> | ||
reader.Read() |> ignore | ||
if reader.TokenType <> JsonTokenType.EndObject then | ||
raise <| JsonException() | ||
Match.Full | ||
| "Partial" -> | ||
// "Amount" key | ||
reader.Read() |> ignore | ||
if reader.TokenType <> JsonTokenType.PropertyName || reader.GetString() <> "Amount" then | ||
raise <| JsonException() | ||
// "Amount" value | ||
let amount = reader.GetDecimal() | ||
reader.Read() |> ignore | ||
if reader.TokenType <> JsonTokenType.EndObject then | ||
raise <| JsonException() | ||
Match.Partial amount | ||
| typeName -> raise <| JsonException("Unknown Match type: " + typeName) | ||
|
||
override this.Write(writer, value, _options ) = | ||
writer.WriteStartObject() | ||
match value with | ||
| Full -> | ||
writer.WriteString("Type", "Full") | ||
| Partial amount -> | ||
writer.WriteString("Type", "Partial") | ||
writer.WriteNumber("Amount", amount) | ||
writer.WriteEndObject() | ||
|
||
let serializationOptions = | ||
let options = JsonSerializerOptions(Redis.Serialization.serializationOptions) | ||
options.Converters.Add(MatchTypeConverter()) | ||
options |
@webwarrior-ws why is this open needed here?