Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Oct 27, 2023
1 parent 9872e7d commit fcdcda5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 31 deletions.
17 changes: 0 additions & 17 deletions src/OSMPBF.jl
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions src/fileformat_pb.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
3 changes: 0 additions & 3 deletions src/osmformat_pb.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
21 changes: 13 additions & 8 deletions src/pbf.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit fcdcda5

Please sign in to comment.