Skip to content

Commit

Permalink
bson_simple for simple namedtuples (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
poncito authored Oct 5, 2022
1 parent ed7432c commit 69e129a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LightBSON"
uuid = "a4a7f996-b3a6-4de6-b9db-2fa5f350df41"
authors = ["Christian Rorvik <christian.rorvik@gmail.com>"]
version = "0.2.14"
version = "0.2.15"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand Down
1 change: 1 addition & 0 deletions src/LightBSON.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ bson_schema_version(::Type{T}) where T = nothing
bson_schema_version_field(::Type{T}) where T = "_v"

bson_simple(::Type{T}) where T = StructTypes.StructType(T) == StructTypes.NoStructType()
bson_simple(::Type{<:NamedTuple}) = true

include("object_id.jl")
include("types.jl")
Expand Down
10 changes: 0 additions & 10 deletions src/writer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,6 @@ function Base.setindex!(writer::BSONWriter, fields::Tuple{Vararg{Pair{String, T}
nothing
end

@generated function Base.setindex!(writer::BSONWriter, fields::T) where T <: NamedTuple
e = Expr(:block)
for fn in fieldnames(T)
fns = "$fn"
push!(e.args, :(writer[$fns] = fields.$fn))
end
push!(e.args, nothing)
e
end

@inline @generated function bson_write_simple(writer::BSONWriter, value::T) where T
fieldcount(T) == 0 && return nothing
totalsize = sum(wire_size_, fieldtypes(T)) + sum(sizeof, fieldnames(T)) + fieldcount(T) * 2
Expand Down

2 comments on commit 69e129a

@ancapdev
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/69564

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.15 -m "<description of version>" 69e129a7984827b16b61dc99d573a28100eaac00
git push origin v0.2.15

Please sign in to comment.