diff --git a/Project.toml b/Project.toml index 055a67a..bd54081 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "LASDatasets" uuid = "cc498e2a-d443-4943-8f26-2a8a0f3c7cdb" authors = ["BenCurran98 "] -version = "0.3.0" +version = "0.3.1" [deps] BufferedStreams = "e1450e63-4bb3-523b-b2a4-4ffa8c0fd77d" @@ -21,7 +21,7 @@ TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9" [compat] BufferedStreams = "1" -ColorTypes = "0.11" +ColorTypes = "0.11, 0.12" DocStringExtensions = "0.9" FileIO = "1" FixedPointNumbers = "0.8" diff --git a/src/vlrs.jl b/src/vlrs.jl index c757454..770de04 100644 --- a/src/vlrs.jl +++ b/src/vlrs.jl @@ -129,6 +129,7 @@ official_record_ids(::Type{TData}) where TData = error("Official record IDs not Get the data type associated with a particular `user_id` and `record_id`. This is used to automatically parse VLR data types on reading +**NOTE**: If the user and record ID combination hasn't been registered, will default to `Vector{UInt8}` and the *VLR* data will be returned as raw bytes. """ function data_type_from_ids(user_id::String, record_id::Integer) registered_vlr_types = get_all_vlr_types() @@ -139,7 +140,9 @@ function data_type_from_ids(user_id::String, record_id::Integer) end end - error("Can't find VLR data type to parse for user ID $(user_id) and record ID $(record_id)") + # if we can't find a registered type, just read it out as a Byte Vector + @warn "Can't find VLR data type to parse for user ID $(user_id) and record ID $(record_id) - reading as raw bytes" + return Vector{UInt8} end function get_all_vlr_types() diff --git a/test/vlrs.jl b/test/vlrs.jl index cde049a..ffa040e 100644 --- a/test/vlrs.jl +++ b/test/vlrs.jl @@ -136,5 +136,50 @@ write(io, vlr) seek(io, 0) @test read(io, LasVariableLengthRecord) == vlr + + # if we haven't registered a VLR type for a struct, we should only read raw bytes back out + struct Thing + a::Int + + b::Float64 + end + + Base.:(==)(t1::Thing, t2::Thing) = (t1.a == t2.a) && (t1.b == t2.b) + + function Base.write(io::IO, thing::Thing) + write(io, thing.a) + write(io, thing.b) + end + + function Base.read(io::IO, ::Type{Thing}) + a = read(io, Int) + b = read(io, Float64) + return Thing(a, b) + end + + thing = Thing(1, 2.0) + # get the bytes for this thing + io = IOBuffer() + write(io, thing) + seek(io, 0) + bytes = read(io) + + # create a VLR - should be able to write it but can't parse it back to a struct if we haven't registered a type + vlr = LasVariableLengthRecord("Thing", 0, "Can't parse!", thing) + + # make sure we can save and load + io = IOBuffer() + write(io, vlr) + seek(io, 0) + out_vlr = read(io, LasVariableLengthRecord) + @test get_data(out_vlr) == bytes + + # if we register a type it should be fine + @register_vlr_type Thing "Thing" 0 + + io = IOBuffer() + write(io, vlr) + seek(io, 0) + @test read(io, LasVariableLengthRecord) == vlr end end \ No newline at end of file