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

Update to ProtoBuf v1 #74

Merged
merged 3 commits into from
Oct 29, 2023
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
Expand Up @@ -24,7 +24,7 @@ HTTP = "^0.7.0, ^0.8.0, ^0.9.0, ^1.2.0"
JSON = "^0.20.0, ^0.21.0"
LibExpat = "^0.6.1"
Graphs = "^1.4.1"
ProtoBuf = "^0.11.5"
ProtoBuf = "1"
StableRNGs = "^1.0.0"
julia = "^1.3.0"

Expand Down
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
131 changes: 90 additions & 41 deletions src/fileformat_pb.jl
Original file line number Diff line number Diff line change
@@ -1,55 +1,104 @@
# Modified from the file automatically generated by ProtoBuf.jl
# See https://github.com/pszufe/OpenStreetMapX.jl/pull/52/
# syntax: proto2
using ProtoBuf
import ProtoBuf.meta
# 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)

mutable struct Blob <: SimpleProtoType
raw_size::Int32
import ProtoBuf as PB
using ProtoBuf: OneOf
using ProtoBuf.EnumX: @enumx

export Blob, BlockHeader

struct Blob
raw::Vector{UInt8}
raw_size::Int32
zlib_data::Vector{UInt8}
lzma_data::Vector{UInt8}
OBSOLETE_bzip2_data::Vector{UInt8}
lz4_data::Vector{UInt8}
zstd_data::Vector{UInt8}
function Blob()
return new()
end
end # mutable struct Blob
const __meta_Blob = Ref{ProtoMeta}()
function meta(::Type{Blob})
ProtoBuf.metalock() do
if !isassigned(__meta_Blob)
__meta_Blob[] = target = ProtoMeta(Blob)
fnum = Int[2,1,3,4,5,6,7]
allflds = Pair{Symbol,Union{Type,String}}[:raw_size => Int32, :raw => Vector{UInt8}, :zlib_data => Vector{UInt8}, :lzma_data => Vector{UInt8}, :OBSOLETE_bzip2_data => Vector{UInt8}, :lz4_data => Vector{UInt8}, :zstd_data => Vector{UInt8}]
oneofs = Int[0,1,1,1,1,1,1]
oneof_names = Symbol[Symbol("data")]
meta(target, Blob, allflds, ProtoBuf.DEF_REQ, fnum, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, oneofs, oneof_names)
bzip2_data::Vector{UInt8}
end
PB.default_values(::Type{Blob}) = (;raw = UInt8[], raw_size = zero(Int32), zlib_data = UInt8[], lzma_data = UInt8[], bzip2_data = UInt8[])
PB.field_numbers(::Type{Blob}) = (;raw = 1, raw_size = 2, zlib_data = 3, lzma_data = 4, bzip2_data = 5)

function PB.decode(d::PB.AbstractProtoDecoder, ::Type{<:Blob})
raw = UInt8[]
raw_size = zero(Int32)
zlib_data = UInt8[]
lzma_data = UInt8[]
bzip2_data = UInt8[]
while !PB.message_done(d)
field_number, wire_type = PB.decode_tag(d)
if field_number == 1
raw = PB.decode(d, Vector{UInt8})
elseif field_number == 2
raw_size = PB.decode(d, Int32)
elseif field_number == 3
zlib_data = PB.decode(d, Vector{UInt8})
elseif field_number == 4
lzma_data = PB.decode(d, Vector{UInt8})
elseif field_number == 5
bzip2_data = PB.decode(d, Vector{UInt8})
else
PB.skip(d, wire_type)
end
__meta_Blob[]
end
return Blob(raw, raw_size, zlib_data, lzma_data, bzip2_data)
end

mutable struct BlobHeader <: SimpleProtoType
_type::AbstractString
function PB.encode(e::PB.AbstractProtoEncoder, x::Blob)
initpos = position(e.io)
!isempty(x.raw) && PB.encode(e, 1, x.raw)
x.raw_size != zero(Int32) && PB.encode(e, 2, x.raw_size)
!isempty(x.zlib_data) && PB.encode(e, 3, x.zlib_data)
!isempty(x.lzma_data) && PB.encode(e, 4, x.lzma_data)
!isempty(x.bzip2_data) && PB.encode(e, 5, x.bzip2_data)
return position(e.io) - initpos
end
function PB._encoded_size(x::Blob)
encoded_size = 0
!isempty(x.raw) && (encoded_size += PB._encoded_size(x.raw, 1))
x.raw_size != zero(Int32) && (encoded_size += PB._encoded_size(x.raw_size, 2))
!isempty(x.zlib_data) && (encoded_size += PB._encoded_size(x.zlib_data, 3))
!isempty(x.lzma_data) && (encoded_size += PB._encoded_size(x.lzma_data, 4))
!isempty(x.bzip2_data) && (encoded_size += PB._encoded_size(x.bzip2_data, 5))
return encoded_size
end

struct BlockHeader
var"#type"::String
indexdata::Vector{UInt8}
datasize::Int32
function BlobHeader()
return new()
end
end # mutable struct BlobHeader
const __meta_BlobHeader = Ref{ProtoMeta}()
function meta(::Type{BlobHeader})
ProtoBuf.metalock() do
if !isassigned(__meta_BlobHeader)
__meta_BlobHeader[] = target = ProtoMeta(BlobHeader)
req = Symbol[:_type,:datasize]
allflds = Pair{Symbol,Union{Type,String}}[:_type => AbstractString, :indexdata => Vector{UInt8}, :datasize => Int32]
meta(target, BlobHeader, allflds, req, ProtoBuf.DEF_FNUM, ProtoBuf.DEF_VAL, ProtoBuf.DEF_PACK, ProtoBuf.DEF_WTYPES, ProtoBuf.DEF_ONEOFS, ProtoBuf.DEF_ONEOF_NAMES)
end
PB.default_values(::Type{BlockHeader}) = (;var"#type" = "", indexdata = UInt8[], datasize = zero(Int32))
PB.field_numbers(::Type{BlockHeader}) = (;var"#type" = 1, indexdata = 2, datasize = 3)

function PB.decode(d::PB.AbstractProtoDecoder, ::Type{<:BlockHeader})
var"#type" = ""
indexdata = UInt8[]
datasize = zero(Int32)
while !PB.message_done(d)
field_number, wire_type = PB.decode_tag(d)
if field_number == 1
var"#type" = PB.decode(d, String)
elseif field_number == 2
indexdata = PB.decode(d, Vector{UInt8})
elseif field_number == 3
datasize = PB.decode(d, Int32)
else
PB.skip(d, wire_type)
end
__meta_BlobHeader[]
end
return BlockHeader(var"#type", indexdata, datasize)
end

export Blob, BlobHeader
function PB.encode(e::PB.AbstractProtoEncoder, x::BlockHeader)
initpos = position(e.io)
!isempty(x.var"#type") && PB.encode(e, 1, x.var"#type")
!isempty(x.indexdata) && PB.encode(e, 2, x.indexdata)
x.datasize != zero(Int32) && PB.encode(e, 3, x.datasize)
return position(e.io) - initpos
end
function PB._encoded_size(x::BlockHeader)
encoded_size = 0
!isempty(x.var"#type") && (encoded_size += PB._encoded_size(x.var"#type", 1))
!isempty(x.indexdata) && (encoded_size += PB._encoded_size(x.indexdata, 2))
x.datasize != zero(Int32) && (encoded_size += PB._encoded_size(x.datasize, 3))
return encoded_size
end
Loading
Loading