From 484435a31874ad00c68fd5040d239cd7ec335646 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 31 Mar 2026 17:51:43 +0000 Subject: [PATCH 1/3] Initial plan From e682fe2cf0833ecdeb1a38a372e34ae6645ce9f0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 31 Mar 2026 18:00:54 +0000 Subject: [PATCH 2/3] Add FixedPointDecimals package extension for FixedDecimal -> Dec128 representation Agent-Logs-Url: https://github.com/ancapdev/LightBSON.jl/sessions/36139d1b-9e70-4c41-8782-69069d79253d Co-authored-by: ancapdev <2189089+ancapdev@users.noreply.github.com> --- Project.toml | 12 ++++++++++-- ext/LightBSONFixedPointDecimalsExt.jl | 15 +++++++++++++++ test/fixed_decimal_tests.jl | 26 ++++++++++++++++++++++++++ test/runtests.jl | 1 + 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 ext/LightBSONFixedPointDecimalsExt.jl create mode 100644 test/fixed_decimal_tests.jl diff --git a/Project.toml b/Project.toml index 0c84a51..6567468 100644 --- a/Project.toml +++ b/Project.toml @@ -20,6 +20,7 @@ WeakRefStrings = "ea10d353-3f73-51f8-a26c-33c1cb351aa5" DataStructures = "0.18, 0.19" Dates = "1" DecFP = "1" +FixedPointDecimals = "0.5, 0.6" FNVHash = "0.1" JSON3 = "1" Sockets = "1" @@ -28,10 +29,17 @@ Transducers = "0.4" UUIDs = "1" UnsafeArrays = "1" WeakRefStrings = "1" -julia = "1.8" +julia = "1.9" + +[weakdeps] +FixedPointDecimals = "fb4d412d-6eee-574d-9565-ede6634db7b0" + +[extensions] +LightBSONFixedPointDecimalsExt = "FixedPointDecimals" [extras] +FixedPointDecimals = "fb4d412d-6eee-574d-9565-ede6634db7b0" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test"] +test = ["Test", "FixedPointDecimals"] diff --git a/ext/LightBSONFixedPointDecimalsExt.jl b/ext/LightBSONFixedPointDecimalsExt.jl new file mode 100644 index 0000000..135f748 --- /dev/null +++ b/ext/LightBSONFixedPointDecimalsExt.jl @@ -0,0 +1,15 @@ +module LightBSONFixedPointDecimalsExt + +using LightBSON +using FixedPointDecimals +using DecFP + +@inline LightBSON.bson_representation_type(::Type{FixedDecimal{T, f}}) where {T, f} = Dec128 + +@inline LightBSON.bson_representation_convert(::Type{Dec128}, x::FixedDecimal{T, f}) where {T, f} = + Dec128(x.i, -f) + +@inline LightBSON.bson_representation_convert(::Type{FixedDecimal{T, f}}, x::Dec128) where {T, f} = + reinterpret(FixedDecimal{T, f}, T(x * Dec128(1, f))) + +end diff --git a/test/fixed_decimal_tests.jl b/test/fixed_decimal_tests.jl new file mode 100644 index 0000000..b232863 --- /dev/null +++ b/test/fixed_decimal_tests.jl @@ -0,0 +1,26 @@ +using FixedPointDecimals + +@testset "FixedDecimal" begin + +@testset "FixedDecimal{Int64, $f} roundtrip" for (f, v) in [(0, 125), (2, 1.25), (4, 1.25)] + buf = empty!(fill(0xff, 1000)) + writer = BSONWriter(buf) + x = FixedDecimal{Int64, f}(v) + writer["x"] = x + close(writer) + @test BSONReader(buf, StrictBSONValidator())["x"][Dec128] == Dec128(x.i, -f) + @test BSONReader(buf, StrictBSONValidator())["x"][FixedDecimal{Int64, f}] == x +end + +@testset "FixedDecimal precise conversion" begin + x = FixedDecimal{Int64, 2}(1.23) + @test Dec128(x.i, -2) == d128"1.23" + buf = empty!(fill(0xff, 1000)) + writer = BSONWriter(buf) + writer["x"] = x + close(writer) + @test BSONReader(buf, StrictBSONValidator())["x"][Dec128] == d128"1.23" + @test BSONReader(buf, StrictBSONValidator())["x"][FixedDecimal{Int64, 2}] == x +end + +end diff --git a/test/runtests.jl b/test/runtests.jl index f07b703..132bedc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -23,4 +23,5 @@ struct EmptyStruct end include("object_id_tests.jl") include("convenience_tests.jl") include("representation_tests.jl") + include("fixed_decimal_tests.jl") end From e700c7b56715272223c610fbff5e7bc491ee72fd Mon Sep 17 00:00:00 2001 From: Christian Rorvik Date: Tue, 31 Mar 2026 21:42:18 +0200 Subject: [PATCH 3/3] Apply suggestion from @ancapdev --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 6567468..4d62a41 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "LightBSON" uuid = "a4a7f996-b3a6-4de6-b9db-2fa5f350df41" authors = ["Christian Rorvik "] -version = "1.4.0" +version = "1.5.0" [deps] DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"