-
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.
Add GrpcModels project for server/client interop
Added GrpcModels project for server/client interop which includes message models (that were in WebSocketApp), as well as Marshalling module (code from RIM).
- Loading branch information
1 parent
fdf1c4e
commit 933bb93
Showing
11 changed files
with
170 additions
and
3 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
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,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Models.fs" /> | ||
<Compile Include="Marshalling.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.Text.Json" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,72 @@ | ||
namespace GrpcModels | ||
|
||
open System | ||
open System.Reflection | ||
open System.Text.Json | ||
|
||
module VersionHelper = | ||
let CURRENT_VERSION = | ||
Assembly | ||
.GetExecutingAssembly() | ||
.GetName() | ||
.Version.ToString() | ||
|
||
type IMarshallingWrapper = | ||
abstract member Value: obj | ||
|
||
type MarshallingWrapper<'T> = | ||
{ | ||
Version: string | ||
TypeName: string | ||
Value: 'T | ||
} | ||
|
||
static member New(value: 'T) = | ||
{ | ||
Value = value | ||
Version = VersionHelper.CURRENT_VERSION | ||
TypeName = typeof<'T>.FullName | ||
} | ||
|
||
interface IMarshallingWrapper with | ||
member this.Value = this.Value :> obj | ||
|
||
module Marshaller = | ||
|
||
let ExtractMetadata(json: string) : Type * Version = | ||
let wrapper = JsonSerializer.Deserialize<MarshallingWrapper<obj>> json | ||
let typ = Type.GetType wrapper.TypeName | ||
let version = Version wrapper.Version | ||
typ, version | ||
|
||
let Serialize<'T>(object: 'T) : string = | ||
let wrapper = MarshallingWrapper.New object | ||
JsonSerializer.Serialize wrapper | ||
|
||
let Deserialize<'T>(json: string) : 'T = | ||
if isNull json then | ||
raise <| ArgumentNullException "json" | ||
|
||
let wrapper = JsonSerializer.Deserialize<MarshallingWrapper<'T>> json | ||
wrapper.Value | ||
|
||
let DeserializeAbstract (json: string) (targetType: Type) : obj = | ||
if isNull json then | ||
raise <| ArgumentNullException "json" | ||
|
||
let wrapperGenericType = typedefof<MarshallingWrapper<_>> | ||
|
||
let wrapperType = | ||
wrapperGenericType.MakeGenericType(Array.singleton targetType) | ||
|
||
let wrapperObj = JsonSerializer.Deserialize(json, wrapperType) | ||
|
||
if isNull wrapperObj then | ||
failwith "Deserialization failed: result is null" | ||
elif wrapperObj.GetType() <> wrapperType then | ||
failwithf | ||
"Deserialization failed, resulting type: %s" | ||
(wrapperObj.GetType().FullName) | ||
|
||
let wrapper = wrapperObj :?> IMarshallingWrapper | ||
wrapper.Value |
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,31 @@ | ||
namespace GrpcModels | ||
|
||
open System | ||
|
||
[<CLIMutable>] | ||
type Message = | ||
{ | ||
Text : string | ||
} | ||
|
||
[<CLIMutable>] | ||
type LimitOrder = | ||
{ | ||
Price: decimal; | ||
Side: string; | ||
Quantity: decimal; | ||
} | ||
|
||
[<CLIMutable>] | ||
type MarketOrder = | ||
{ | ||
Side: string; | ||
Quantity: decimal; | ||
} | ||
|
||
[<CLIMutable>] | ||
type CancelOrderRequest = | ||
{ | ||
OrderId: Guid; | ||
// TODO: add Market | ||
} |
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