From fcdcda5e94b5fb172d319cfa5ff3a44e0ace1f5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Fri, 27 Oct 2023 11:03:08 +0200 Subject: [PATCH] Fixes --- src/OSMPBF.jl | 17 ----------------- src/fileformat_pb.jl | 3 --- src/osmformat_pb.jl | 3 --- src/pbf.jl | 21 +++++++++++++-------- 4 files changed, 13 insertions(+), 31 deletions(-) diff --git a/src/OSMPBF.jl b/src/OSMPBF.jl index 1c03b63..0e22e06 100644 --- a/src/OSMPBF.jl +++ b/src/OSMPBF.jl @@ -1,21 +1,4 @@ -# Modified from the file automatically generated by ProtoBuf.jl -# See https://github.com/pszufe/OpenStreetMapX.jl/pull/52/ module OSMPBF - const _ProtoBuf_Top_ = @static isdefined(parentmodule(@__MODULE__), :_ProtoBuf_Top_) ? (parentmodule(@__MODULE__))._ProtoBuf_Top_ : parentmodule(@__MODULE__) - - using ProtoBuf - abstract type SimpleProtoType <: ProtoType end - set_defaults!(::SimpleProtoType) = nothing - function ProtoBuf.clear(obj::SimpleProtoType) - # FIXME how does it play with GC ? - Base.unsafe_securezero!(pointer_from_objref(obj), sizeof(typeof(obj))) - set_defaults!(obj) - return - end - Base.hasproperty(obj::SimpleProtoType, field::Symbol) = isdefined(obj, field) - Base.setproperty!(obj::SimpleProtoType, field::Symbol, value) = setfield!(obj, field, value) - ProtoBuf.setdefaultproperties!(::SimpleProtoType, ::ProtoMeta) = nothing - include("fileformat_pb.jl") include("osmformat_pb.jl") end diff --git a/src/fileformat_pb.jl b/src/fileformat_pb.jl index 375beff..ff51fba 100644 --- a/src/fileformat_pb.jl +++ b/src/fileformat_pb.jl @@ -1,8 +1,6 @@ # Autogenerated using ProtoBuf.jl v1.0.14 on 2023-10-26T22:07:48.079 # original file: https://raw.githubusercontent.com/osmandapp/OsmAnd-resources/master/protos/fileformat.proto (proto2 syntax) -module fileformat_pb - import ProtoBuf as PB using ProtoBuf: OneOf using ProtoBuf.EnumX: @enumx @@ -104,4 +102,3 @@ function PB._encoded_size(x::BlockHeader) x.datasize != zero(Int32) && (encoded_size += PB._encoded_size(x.datasize, 3)) return encoded_size end -end # module diff --git a/src/osmformat_pb.jl b/src/osmformat_pb.jl index 0e710af..0e63680 100644 --- a/src/osmformat_pb.jl +++ b/src/osmformat_pb.jl @@ -1,8 +1,6 @@ # Autogenerated using ProtoBuf.jl v1.0.14 on 2023-10-26T22:05:46.147 # original file: https://raw.githubusercontent.com/osmandapp/OsmAnd-resources/master/protos/osmformat.proto (proto2 syntax) -module osmformat_pb - import ProtoBuf as PB using ProtoBuf: OneOf using ProtoBuf.EnumX: @enumx @@ -629,4 +627,3 @@ function PB._encoded_size(x::PrimitiveBlock) x.date_granularity != Int32(1000) && (encoded_size += PB._encoded_size(x.date_granularity, 18)) return encoded_size end -end # module diff --git a/src/pbf.jl b/src/pbf.jl index cf8df3f..7e275bd 100644 --- a/src/pbf.jl +++ b/src/pbf.jl @@ -1,23 +1,28 @@ include("OSMPBF.jl") -using ProtoBuf, CodecZlib +import CodecZlib const BLOCK = Dict( - "OSMHeader" => OSMPBF.HeaderBlock(), - "OSMData" => OSMPBF.PrimitiveBlock(), + "OSMHeader" => OSMPBF.HeaderBlock, + "OSMData" => OSMPBF.PrimitiveBlock, ) +function _decode(str, ::Type{T}) where {T} + io = IOBuffer(str) + d = OSMPBF.PB.ProtoDecoder(io) + return OSMPBF.PB.decode(d, T) +end + function parseblob(io::IO) len = ntoh(read(io, Int32)) h = read(io, len) - bh = readproto(IOBuffer(h), OSMPBF.BlobHeader()) - blob_buf = IOBuffer(read(io, bh.datasize)) - b = readproto(blob_buf, OSMPBF.Blob()) - ok = transcode(ZlibDecompressor, b.zlib_data) + bh = _decode(h, OSMPBF.BlockHeader) + b = _decode(read(io, bh.datasize), OSMPBF.Blob) + ok = CodecZlib.transcode(CodecZlib.ZlibDecompressor, b.zlib_data) if length(ok) != b.raw_size @warn("Uncompressed size $(length(ok)) bytes does not match $(b.raw_size).") end - readproto(IOBuffer(ok), BLOCK[bh._type]) + return _decode(ok, BLOCK[bh.var"#type"]) end function process_block(osm::OSMData, block::OSMPBF.HeaderBlock)