Conversation
Replace `LMDB.mdb_unpack(::Type{T}, ::Ref{MDB_val})` — the package's
typed-read customization point — with a plain `IO` view over the
LMDB-owned `MDB_val`. Users now plug in custom decoders by defining
the idiomatic `Base.read(io::IO, ::Type{MyType})`, which works against
any byte stream and is the convention every other Julia decoder uses.
struct PrefixedBlob end
function Base.read(io::IO, ::Type{PrefixedBlob})
skip(io, 8)
return read(io, String)
end
LMDB.tryget(txn, dbi, key, PrefixedBlob)
`MDBValueIO <: IO` exposes `position` / `seek` / `seekstart` / `seekend`
/ `skip` / `bytesavailable` / `eof` and overrides `unsafe_read` so
Base's primitive `read(io, T)` for `Int8…Float64`/`Bool`/`Char`/`Ptr`
inherits zero-allocation. The default `read(io, String)` and
`read(io, Vector{E})` consume the rest of the buffer and copy out.
Internal call sites in `cur.jl` / `dbi.jl` / `dicts.jl` switch from
`mdb_unpack(T, ref)` to `read(MDBValueIO(ref[]), T)`. The package
exposes `LMDB.MDBValueIO` for users who override `Base.read`.
`mdb_unpack` is dropped — breaking change for the (rare) caller who
defined their own `mdb_unpack` method.
Preserves PR #52's GC-safety fix: `common.jl` keeps the
deferred-pointer-extraction pattern from #52 (the upstream commit
this is based on pre-dates that fix). `MDBValue(::String)` and the
eager-extraction variants stay deleted; `cconvert(::Ptr{MDB_val}, x)`
returns an `MDBArg` carrier with an uninitialized box, and
`unsafe_convert(::Ptr{MDB_val}, ::MDBArg{D})` does the extraction
inside ccall's preserve window.
Tested locally on Julia 1.10, 1.11, 1.12, 1.13.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #55 +/- ##
==========================================
- Coverage 83.40% 82.11% -1.29%
==========================================
Files 9 9
Lines 717 755 +38
==========================================
+ Hits 598 620 +22
- Misses 119 135 +16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace
LMDB.mdb_unpack(::Type{T}, ::Ref{MDB_val})— the package's typed-read customization point — with a plainIOview over the LMDB-ownedMDB_val. Users now plug in custom decoders by defining the idiomaticBase.read(io::IO, ::Type{MyType}), which works against any byte stream and is the convention every other Julia decoder uses.MDBValueIO <: IOexposesposition/seek/seekstart/seekend/skip/bytesavailable/eofand overridesunsafe_readso Base's primitiveread(io, T)forInt8…Float64/Bool/Char/Ptrinherits zero-allocation. The defaultread(io, String)andread(io, Vector{E})consume the rest of the buffer and copy out.Internal call sites in
cur.jl/dbi.jl/dicts.jlswitch frommdb_unpack(T, ref)toread(MDBValueIO(ref[]), T). The package exposesLMDB.MDBValueIOfor users who overrideBase.read.Last piece of functionality I had locally, will focus on cleaning up things tomorrow.