Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

partial parsing #28

Merged
merged 3 commits into from
Dec 13, 2022
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
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.15"
version = "0.2.16"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand Down
4 changes: 4 additions & 0 deletions src/reader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ function read_field_(reader::AbstractBSONReader, ::Type{Vector{T}}) where T
copy!(dst, reader)
end

function read_field_(reader::T, ::Type{<:Union{T, AbstractBSONReader}}) where {T <: AbstractBSONReader}
reader
end

function Base.copy!(dst::AbstractArray{T}, reader::AbstractBSONReader) where T
copy!(Map(x -> x.second[T]), dst, reader)
end
Expand Down
10 changes: 10 additions & 0 deletions test/reader_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,14 @@ end
@test sizeof(reader) == 19
end

@testset "getindex AbstractBSONReader" begin
buf = UInt8[]
writer = BSONWriter(buf)
writer["x"] = 123
close(writer)
reader = BSONReader(buf)
@test reader["x"][AbstractBSONReader] == reader["x"]
@test reader["x"][typeof(reader)] == reader["x"]
end

end
25 changes: 24 additions & 1 deletion test/struct_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,30 @@ end
writer[] = x
close(writer)
reader = BSONReader(buf)
reader[typeof(x)] == x
@test reader[typeof(x)] == x
Copy link
Contributor Author

Choose a reason for hiding this comment

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

missing @test?

Copy link
Owner

Choose a reason for hiding this comment

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

Looks like it

end

struct Parametric{T}
type_encoding::Int
payload::T
end

@testset "AbstractBSONReader" begin
buf = UInt8[]
writer = BSONWriter(buf)
x = (; type_encoding = 1, payload = "test")
writer[] = x
close(writer)
reader = BSONReader(buf)
p = reader[Parametric{AbstractBSONReader}]
@test p.type_encoding == 1
@test p.payload isa AbstractBSONReader
p.payload[String] == "test"

p = reader[Parametric{typeof(reader)}]
@test p.type_encoding == 1
@test p.payload isa AbstractBSONReader
p.payload[String] == "test"
end

end