Skip to content

Commit

Permalink
Use concrete types instead of dictionaries (#52)
Browse files Browse the repository at this point in the history
* Use concrete types instead of dictionaries

* Modify generated header

* Replace ccall by Base helper
  • Loading branch information
blegat authored Aug 29, 2021
1 parent 4241659 commit 87ce7e4
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 487 deletions.
17 changes: 16 additions & 1 deletion src/OSMPBF.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Automatically generated by ProtoBuf.jl
# 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
85 changes: 18 additions & 67 deletions src/fileformat_pb.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
# Automatically generated by ProtoBuf.jl
# 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

mutable struct Blob <: ProtoType
__protobuf_jl_internal_meta::ProtoMeta
__protobuf_jl_internal_values::Dict{Symbol,Any}
__protobuf_jl_internal_defaultset::Set{Symbol}

function Blob(; kwargs...)
obj = new(meta(Blob), Dict{Symbol,Any}(), Set{Symbol}())
values = obj.__protobuf_jl_internal_values
symdict = obj.__protobuf_jl_internal_meta.symdict
for nv in kwargs
fldname, fldval = nv
fldtype = symdict[fldname].jtyp
(fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
if fldval !== nothing
values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
end
end
obj
mutable struct Blob <: SimpleProtoType
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}
function Blob()
return new()
end
end # mutable struct Blob
const __meta_Blob = Ref{ProtoMeta}()
Expand All @@ -37,44 +30,13 @@ function meta(::Type{Blob})
__meta_Blob[]
end
end
function Base.getproperty(obj::Blob, name::Symbol)
if name === :raw_size
return (obj.__protobuf_jl_internal_values[name])::Int32
elseif name === :raw
return (obj.__protobuf_jl_internal_values[name])::Vector{UInt8}
elseif name === :zlib_data
return (obj.__protobuf_jl_internal_values[name])::Vector{UInt8}
elseif name === :lzma_data
return (obj.__protobuf_jl_internal_values[name])::Vector{UInt8}
elseif name === :OBSOLETE_bzip2_data
return (obj.__protobuf_jl_internal_values[name])::Vector{UInt8}
elseif name === :lz4_data
return (obj.__protobuf_jl_internal_values[name])::Vector{UInt8}
elseif name === :zstd_data
return (obj.__protobuf_jl_internal_values[name])::Vector{UInt8}
else
getfield(obj, name)
end
end

mutable struct BlobHeader <: ProtoType
__protobuf_jl_internal_meta::ProtoMeta
__protobuf_jl_internal_values::Dict{Symbol,Any}
__protobuf_jl_internal_defaultset::Set{Symbol}

function BlobHeader(; kwargs...)
obj = new(meta(BlobHeader), Dict{Symbol,Any}(), Set{Symbol}())
values = obj.__protobuf_jl_internal_values
symdict = obj.__protobuf_jl_internal_meta.symdict
for nv in kwargs
fldname, fldval = nv
fldtype = symdict[fldname].jtyp
(fldname in keys(symdict)) || error(string(typeof(obj), " has no field with name ", fldname))
if fldval !== nothing
values[fldname] = isa(fldval, fldtype) ? fldval : convert(fldtype, fldval)
end
end
obj
mutable struct BlobHeader <: SimpleProtoType
_type::AbstractString
indexdata::Vector{UInt8}
datasize::Int32
function BlobHeader()
return new()
end
end # mutable struct BlobHeader
const __meta_BlobHeader = Ref{ProtoMeta}()
Expand All @@ -89,16 +51,5 @@ function meta(::Type{BlobHeader})
__meta_BlobHeader[]
end
end
function Base.getproperty(obj::BlobHeader, name::Symbol)
if name === :_type
return (obj.__protobuf_jl_internal_values[name])::AbstractString
elseif name === :indexdata
return (obj.__protobuf_jl_internal_values[name])::Vector{UInt8}
elseif name === :datasize
return (obj.__protobuf_jl_internal_values[name])::Int32
else
getfield(obj, name)
end
end

export Blob, BlobHeader
Loading

0 comments on commit 87ce7e4

Please sign in to comment.