So unless you are doing meta-analysis of the raw OSM data, without assembling geometries, hand-rolling an OSMPBF reader is viable, otherwise I would suggest either using something pre-processed (extracts in real geodata formats), an established parser like osmium or rather import the data into e.g. postgres and do some querying there.
* https://osmcode.org/osmium-tool/manual.html
And you can convert osm.pbf to osm.opl - and can reprocess with unix tools (grep,awk,cut,tr,...):