Closed karsten42 closed 7 years ago
@karsten42 thanks for this! Have you thought about just having the Decode()
return a *osmpbf.Header
, just like it returns *osmpbf.Way
etc instead of having a separate Header()
function? I understand that only one *osmpbf.Header
will be returned but to me if feels more natural with the way the API is right now. What do you think @AlekSi?
Yes, I thought about that. But then there is now way of getting the header before you start going through the file, right? In my application I actually get the header before reading the file to change some parameters.
Decode reads the next object from the input stream and returns either a pointer to Node, Way or Relation struct representing the underlying OpenStreetMap PBF data, or error encountered.
I think it's too late to break public API after 1.0 even if the signature is not changed. A quick check of https://godoc.org/github.com/qedus/osmpbf?importers showed that people use switch
over interface{}
with default
section, this will change a behavior.
@karsten42 and @AlekSi both good points! I concede.
@AlekSi I made your suggested changes. Good remark using sync.Once. I also fixed the tests I broke (shame on me).
@jongillham PTAL.
@jongillham All very good remarks! I adapted the code accordingly.
As far as I could see there was no way so far to get hand on the OSM header information. It was only being decoded to check if the parser is capable of processing the file. I added the possibility to get the header via the decoder which reads it from the file and stores it in the struct. The header will only be read one time from the file.