@Override
    public OsmElement.Node next() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      // Delta decode node fields.
      nodeId += nodes.getId(i);
      latitude += nodes.getLat(i);
      longitude += nodes.getLon(i);
      int version = 0;

      if (denseInfo != null) {
        version = denseInfo.getVersionCount() > i ? denseInfo.getVersion(i) : 0;
        timestamp += denseInfo.getTimestampCount() > i ? denseInfo.getTimestamp(i) : 0;
        changeset += denseInfo.getChangesetCount() > i ? denseInfo.getChangeset(i) : 0;
        uid += denseInfo.getUidCount() > i ? denseInfo.getUid(i) : 0;
        userSid += denseInfo.getUserSidCount() > i ? denseInfo.getUserSid(i) : 0;
      }

      i++;

      // Build the tags. The key and value string indexes are sequential
      // in the same PBF array. Each set of tags is delimited by an index
      // with a value of 0.
      Map<String, Object> tags = null;
      while (kvIndex < nodes.getKeysValsCount()) {
        int keyIndex = nodes.getKeysVals(kvIndex++);
        if (keyIndex == 0) {
          break;
        }
        int valueIndex = nodes.getKeysVals(kvIndex++);

        if (tags == null) {
          // divide by 2 as key&value, multiply by 2 because of the better approximation
          tags = HashMap.newHashMap(Math.max(3, 2 * (nodes.getKeysValsCount() / 2) / nodes.getKeysValsCount()));
        }

        tags.put(fieldDecoder.decodeString(keyIndex), fieldDecoder.decodeString(valueIndex));
      }

      return new OsmElement.Node(
        nodeId,
        tags == null ? Collections.emptyMap() : tags,
        ((double) latitude) / 10000000,
        ((double) longitude) / 10000000,
        denseInfo == null ? null : new OsmElement.Info(
          changeset,
          timestamp,
          uid,
          version,
          fieldDecoder.decodeString(userSid)
        )
      );
    }
Decompresses and parses a header block of an OSM input file.
planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/PbfDecoder.java