Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/bson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#

# BSONType mirrors C enum bson_type_t.
primitive type BSONType 8 end # 1 byte
primitive type BSONType sizeof(Cint) * 8 end

Base.convert(::Type{T}, t::BSONType) where {T<:Number} = reinterpret(UInt8, t)
Base.convert(::Type{BSONType}, n::T) where {T<:Number} = reinterpret(BSONType, n)
Base.convert(::Type{T}, t::BSONType) where {T<:Number} = T(reinterpret(Cint, t))
Base.convert(::Type{BSONType}, n::T) where {T<:Number} = reinterpret(BSONType, Cint(n))
BSONType(u::UInt8) = convert(BSONType, u)

#
Expand Down Expand Up @@ -40,10 +40,10 @@ const BSON_TYPE_MINKEY = BSONType(0xFF)


# BSONSubType mirrors C enum bson_subtype_t.
primitive type BSONSubType 8 end
primitive type BSONSubType sizeof(Cint) * 8 end

Base.convert(::Type{T}, t::BSONSubType) where {T<:Number} = reinterpret(UInt8, t)
Base.convert(::Type{BSONSubType}, n::T) where {T<:Number} = reinterpret(BSONSubType, n)
Base.convert(::Type{T}, t::BSONSubType) where {T<:Number} = T(reinterpret(Cint, t))
Base.convert(::Type{BSONSubType}, n::T) where {T<:Number} = reinterpret(BSONSubType, Cint(n))
BSONSubType(u::UInt8) = convert(BSONSubType, u)

#
Expand Down
20 changes: 20 additions & 0 deletions test/bson_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ using Distributed
@test bson["uuid2"] == uuid
end

@testset "Binary data iteration (#145)" begin
# This would segfault on Julia 1.12 before the enum size fix
b = Mongoc.BSON("a" => UInt8[0x1, 0x2, 0x3])

# Test iteration
result = iterate(b)
@test result !== nothing
(pair, state) = result
@test pair.first == "a"
@test pair.second == UInt8[0x1, 0x2, 0x3]

# Test Dict conversion (uses iteration internally)
d = Dict(b)
@test d["a"] == UInt8[0x1, 0x2, 0x3]

# Test as_dict
d2 = Mongoc.as_dict(b)
@test d2["a"] == UInt8[0x1, 0x2, 0x3]
end

@testset "BSON key/values itr support" begin
bson = Mongoc.BSON()
bson["hey"] = 10
Expand Down
Loading