From 6a4802dd23d6186d9b4899b60f5257b930aeba84 Mon Sep 17 00:00:00 2001 From: Ruben Bartelink Date: Sat, 7 Sep 2024 17:58:27 +0100 Subject: [PATCH] Restore binary compatibility --- .../CosmosStoreSerialization.fs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Equinox.CosmosStore/CosmosStoreSerialization.fs b/src/Equinox.CosmosStore/CosmosStoreSerialization.fs index 79d198d5a..fd1075932 100644 --- a/src/Equinox.CosmosStore/CosmosStoreSerialization.fs +++ b/src/Equinox.CosmosStore/CosmosStoreSerialization.fs @@ -31,6 +31,23 @@ module JsonElement = if value.ValueKind = JsonValueKind.Null then value else value |> toUtf8Bytes |> Deflate.compress |> JsonSerializer.SerializeToElement +[] +type CosmosJsonSerializer(options : JsonSerializerOptions) = + inherit Microsoft.Azure.Cosmos.CosmosSerializer() + + override _.FromStream<'T>(stream) = + use _ = stream + + if stream.Length = 0L then Unchecked.defaultof<'T> + elif typeof.IsAssignableFrom(typeof<'T>) then box stream :?> 'T + else JsonSerializer.Deserialize<'T>(stream, options) + + override _.ToStream<'T>(input : 'T) = + let memoryStream = new MemoryStream() + JsonSerializer.Serialize(memoryStream, input, input.GetType(), options) + memoryStream.Position <- 0L + memoryStream :> Stream + /// Manages inflating of the UTF-8 json bytes to make the index record minimal from the perspective of the writer stored proc /// Only relevant for unfolds in the Tip type JsonCompressedBase64Converter() =