parse_values(ctx);
}
-/**
- * Finalize aggregation.
- *
- * Encode keys and values and put the aggregated Layer message into
- * a Tile message and returns it packed as a bytea.
- */
-uint8_t *mvt_agg_finalfn(struct mvt_agg_context *ctx)
+static bytea *mvt_ctx_to_bytea(struct mvt_agg_context *ctx)
{
- VectorTile__Tile__Layer *layers[1];
- VectorTile__Tile tile = VECTOR_TILE__TILE__INIT;
- size_t len;
- uint8_t *buf;
+ /* Fill out the file slot, if it's not already filled. */
+ /* We should only have a filled slow when all the work of building */
+ /* out the data is complete, so after a serialize/deserialize cycle */
+ /* or after a context combine */
+ if (!ctx->tile)
+ {
+ VectorTile__Tile__Layer **layers = ;
+ VectorTile__Tile tile = VECTOR_TILE__TILE__INIT;
+
+ POSTGIS_DEBUG(2, "mvt_agg_finalfn called");
+ POSTGIS_DEBUGF(2, "mvt_agg_finalfn n_features == %zd", ctx->layer->n_features);
+
+ /* Zero features => empty bytea output */
+ if (ctx->layer->n_features == 0)
+ {
+ buf = palloc(VARHDRSZ);
+ SET_VARSIZE(buf, VARHDRSZ);
+ return buf;
+ }
- POSTGIS_DEBUG(2, "mvt_agg_finalfn called");
- POSTGIS_DEBUGF(2, "mvt_agg_finalfn n_features == %zd", ctx->layer->n_features);
+ encode_keys(ctx);
+ encode_values(ctx);
- /* Zero features => empty bytea output */
- if (ctx->layer->n_features == 0)
- {
- buf = palloc(VARHDRSZ);
- SET_VARSIZE(buf, VARHDRSZ);
- return buf;
+ int n_layers = 1;
+ ctx->tile = palloc(sizeof(VectorTile__Tile));
+ vector_tile__tile__init(ctx->tile);
+ ctx->tile->layers = palloc(sizeof(VectorTile__Tile__Layer*) * n_layers);
+ ctx->tile->layers[0] = ctx->layer;
+ ctx->tile->n_layers = n_layers;
}
- encode_keys(ctx);
- encode_values(ctx);
+ /* Serialize the Tile */
+ size_t len = VARHDRSZ + vector_tile__tile__get_packed_size(ctx->tile);
+ bytea *ba = palloc(len);
+ vector_tile__tile__pack(ctx->tile, VARDATA(ba));
+ SET_VARSIZE(ba, len);
+ return ba;
+}
- layers[0] = ctx->layer;
- tile.n_layers = 1;
- tile.layers = layers;
+bytea *mvt_ctx_serialize(struct mvt_agg_context *ctx)
+{
+ return mvt_ctx_to_bytea(ctx);
+}
- len = vector_tile__tile__get_packed_size(&tile);
- buf = palloc(sizeof(*buf) * (len + VARHDRSZ));
- vector_tile__tile__pack(&tile, buf + VARHDRSZ);
+mvt_agg_context * mvt_ctx_deserialize(const bytea *ba)
+{
- SET_VARSIZE(buf, VARHDRSZ + len);
+}
- return buf;
+/**
+ * Finalize aggregation.
+ *
+ * Encode keys and values and put the aggregated Layer message into
+ * a Tile message and returns it packed as a bytea.
+ */
+bytea *mvt_agg_finalfn(struct mvt_agg_context *ctx)
+{
+ return mvt_ctx_to_bytea(ctx);
}
+
#endif
CREATE OR REPLACE FUNCTION pgis_asmvt_transfn(internal, anyelement)
RETURNS internal
AS 'MODULE_PATHNAME', 'pgis_asmvt_transfn'
- LANGUAGE c IMMUTABLE _PARALLEL;
+ LANGUAGE 'c' IMMUTABLE _PARALLEL;
-- Availability: 2.4.0
CREATE OR REPLACE FUNCTION pgis_asmvt_transfn(internal, anyelement, text)
RETURNS internal
AS 'MODULE_PATHNAME', 'pgis_asmvt_transfn'
- LANGUAGE c IMMUTABLE _PARALLEL;
+ LANGUAGE 'c' IMMUTABLE _PARALLEL;
-- Availability: 2.4.0
CREATE OR REPLACE FUNCTION pgis_asmvt_transfn(internal, anyelement, text, int4)
RETURNS internal
AS 'MODULE_PATHNAME', 'pgis_asmvt_transfn'
- LANGUAGE c IMMUTABLE _PARALLEL;
+ LANGUAGE 'c' IMMUTABLE _PARALLEL;
-- Availability: 2.4.0
CREATE OR REPLACE FUNCTION pgis_asmvt_transfn(internal, anyelement, text, int4, text)
RETURNS internal
AS 'MODULE_PATHNAME', 'pgis_asmvt_transfn'
- LANGUAGE c IMMUTABLE _PARALLEL;
+ LANGUAGE 'c' IMMUTABLE _PARALLEL;
-- Availability: 2.4.0
CREATE OR REPLACE FUNCTION pgis_asmvt_finalfn(internal)
RETURNS bytea
AS 'MODULE_PATHNAME', 'pgis_asmvt_finalfn'
- LANGUAGE c IMMUTABLE _PARALLEL;
+ LANGUAGE 'c' IMMUTABLE _PARALLEL;
-- Availability: 2.4.0
CREATE AGGREGATE ST_AsMVT(anyelement)
CREATE OR REPLACE FUNCTION pgis_asgeobuf_transfn(internal, anyelement)
RETURNS internal
AS 'MODULE_PATHNAME', 'pgis_asgeobuf_transfn'
- LANGUAGE c IMMUTABLE _PARALLEL;
+ LANGUAGE 'c' IMMUTABLE _PARALLEL;
-- Availability: 2.4.0
CREATE OR REPLACE FUNCTION pgis_asgeobuf_transfn(internal, anyelement, text)
RETURNS internal
AS 'MODULE_PATHNAME', 'pgis_asgeobuf_transfn'
- LANGUAGE c IMMUTABLE _PARALLEL;
+ LANGUAGE 'c' IMMUTABLE _PARALLEL;
-- Availability: 2.4.0
CREATE OR REPLACE FUNCTION pgis_asgeobuf_finalfn(internal)
RETURNS bytea
AS 'MODULE_PATHNAME', 'pgis_asgeobuf_finalfn'
- LANGUAGE c IMMUTABLE _PARALLEL;
+ LANGUAGE 'c' IMMUTABLE _PARALLEL;
-- Availability: 2.4.0
CREATE AGGREGATE ST_AsGeobuf(anyelement)