Skip to content

Commit

Permalink
Handle TryDeflate encoding (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink authored Jul 6, 2022
1 parent 9434928 commit 4affa4e
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Propulsion.CosmosStore/Propulsion.CosmosStore.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

<PackageReference Include="FSharp.Core" Version="4.5.4" />

<PackageReference Include="Equinox.CosmosStore" Version="4.0.0-beta.7.1" />
<PackageReference Include="FsCodec.SystemTextJson" Version="3.0.0-rc.2.2" />
<PackageReference Include="Equinox.CosmosStore" Version="4.0.0-beta.9" />
<PackageReference Include="FsCodec.SystemTextJson" Version="3.0.0-rc.4" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Propulsion.CosmosStore/ReaderCheckpoint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Events =
| Snapshotted of Snapshotted
interface TypeShape.UnionContract.IUnionContract
#if DYNAMOSTORE
let codec = FsCodec.SystemTextJson.Codec.Create<Event>()
let codec = FsCodec.SystemTextJson.Codec.Create<Event>() |> FsCodec.Deflate.EncodeTryDeflate
#else
#if !COSMOSV3 && !COSMOSV2
let codec = FsCodec.SystemTextJson.CodecJsonElement.Create<Event>()
Expand Down
7 changes: 4 additions & 3 deletions src/Propulsion.DynamoStore/DynamoStoreSource.fs
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,17 @@ type LoadMode =
* /// Defines the Context to use when loading the bodies
storeContext : DynamoStoreContext
module internal LoadMode =
let private mapBodyToBytes = (fun (x : System.ReadOnlyMemory<byte>) -> x.ToArray())
let private mapTimelineEvent = FsCodec.Core.TimelineEvent.Map mapBodyToBytes
let private mapTimelineEvent =
let mapBodyToBytes = (fun (x : System.ReadOnlyMemory<byte>) -> x.ToArray())
FsCodec.Core.TimelineEvent.Map (FsCodec.Deflate.EncodedToUtf8 >> mapBodyToBytes) // TODO replace with FsCodec.Deflate.EncodedToByteArray
let private withBodies (eventsContext : Equinox.DynamoStore.Core.EventsContext) filter =
fun sn (i, cs : string array) ->
if filter sn then Some (async { let! _pos, events = eventsContext.Read(FsCodec.StreamName.toString sn, i, maxCount = cs.Length)
return events |> Array.map mapTimelineEvent })
else None
let private withoutBodies filter =
fun sn (i, cs) ->
let render = async { return cs |> Array.mapi (fun offset c -> FsCodec.Core.TimelineEvent.Create(i + int64 offset, eventType = c, data = null)) }
let render = async { return cs |> Array.mapi (fun offset c -> FsCodec.Core.TimelineEvent.Create(i + int64 offset, eventType = c, data = Unchecked.defaultof<_>)) }
if filter sn then Some render else None
let map storeLog : LoadMode -> _ = function
| All -> false, withoutBodies (fun _ -> true), 1
Expand Down
4 changes: 2 additions & 2 deletions src/Propulsion.DynamoStore/Propulsion.DynamoStore.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

<PackageReference Include="FSharp.Core" Version="4.7.2" />

<PackageReference Include="Equinox.DynamoStore" Version="4.0.0-beta.7.1" />
<PackageReference Include="FsCodec.SystemTextJson" Version="3.0.0-rc.2.2" />
<PackageReference Include="Equinox.DynamoStore" Version="4.0.0-beta.9" />
<PackageReference Include="FsCodec.SystemTextJson" Version="3.0.0-rc.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Propulsion.Feed\Propulsion.Feed.fsproj" />
Expand Down
4 changes: 2 additions & 2 deletions src/Propulsion.DynamoStore/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ module internal Config =
module internal EventCodec =

let create<'t when 't :> TypeShape.UnionContract.IUnionContract> () =
FsCodec.SystemTextJson.Codec.Create<'t>()
FsCodec.SystemTextJson.Codec.Create<'t>() |> FsCodec.Deflate.EncodeTryDeflate
let private withUpconverter<'c, 'e when 'c :> TypeShape.UnionContract.IUnionContract> up : FsCodec.IEventCodec<'e, _, _> =
let down (_ : 'e) = failwith "Unexpected"
FsCodec.SystemTextJson.Codec.Create<'e, 'c, _>(up, down)
FsCodec.SystemTextJson.Codec.Create<'e, 'c, _>(up, down) |> FsCodec.Deflate.EncodeTryDeflate
let withIndex<'c when 'c :> TypeShape.UnionContract.IUnionContract> : FsCodec.IEventCodec<int64 * 'c, _, _> =
let up (raw : FsCodec.ITimelineEvent<_>, e) = raw.Index, e
withUpconverter<'c, int64 * 'c> up
Expand Down
2 changes: 1 addition & 1 deletion src/Propulsion.EventStoreDb/Propulsion.EventStoreDb.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<PackageReference Include="FSharp.Core" Version="4.5.4" />

<PackageReference Include="Equinox.EventStoreDb" Version="4.0.0-beta.7.1" />
<PackageReference Include="Equinox.EventStoreDb" Version="4.0.0-beta.9" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Destructurama.FSharp.NetCore" Version="1.0.14" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="unquote" Version="6.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
Expand Down

0 comments on commit 4affa4e

Please sign in to comment.