private byte[] encodeValue(VectorTile.Feature vectorTileFeature, RenderedFeature.Group group,
    MessageBufferPacker packer) {
    packer.clear();
    try {
      // hasGroup bit in key will tell consumers whether they need to decode group info from value
      if (group != null) {
        packer.packLong(group.group());
        packer.packInt(group.limit());
      }
      packer.packLong(vectorTileFeature.id());
      packer.packByte(encodeGeomTypeAndScale(vectorTileFeature.geometry()));
      var attrs = vectorTileFeature.tags();
      packer.packMapHeader((int) attrs.values().stream().filter(Objects::nonNull).count());
      for (Map.Entry<String, Object> entry : attrs.entrySet()) {
        Object value = entry.getValue();
        if (value != null) {
          packer.packInt(commonValueStrings.encode(entry.getKey()));
          packer.packValue(switch (value) {
            case String string -> ValueFactory.newString(string);
            case Integer integer -> ValueFactory.newInteger(integer.longValue());
            case Long longValue -> ValueFactory.newInteger(longValue);
            case Float floatValue -> ValueFactory.newFloat(floatValue);
            case Double doubleValue -> ValueFactory.newFloat(doubleValue);
            case Boolean booleanValue -> ValueFactory.newBoolean(booleanValue);
            case Object other -> ValueFactory.newString(other.toString());
          });
        }
      }
      // Use the same binary format for encoding geometries in output vector tiles. Benchmarking showed
      // it was faster and smaller for encoding/decoding intermediate geometries than alternatives like WKB.
      int[] commands = vectorTileFeature.geometry().commands();
      packer.packArrayHeader(commands.length);
      for (int command : commands) {
        packer.packInt(command);
      }
      packer.close();
    } catch (IOException e) {
      throw new IllegalStateException(e);
    }
    return packer.toByteArray();
  }
Returns a function for a single thread to use to serialize rendered features.
planetiler-core/src/main/java/com/onthegomap/planetiler/collection/FeatureGroup.java