From 70325a6982bf2233956a07b68254dada9317f7e6 Mon Sep 17 00:00:00 2001 From: The-Alchemist Date: Sat, 26 May 2018 23:10:31 -0400 Subject: [PATCH 1/2] Trying bytea->pcpoint conversion Signed-off-by: The-Alchemist --- pgsql/pc_inout.c | 28 ++++++++++++++++++++++++++++ pgsql/pointcloud.sql.in | 13 +++++++++++++ 2 files changed, 41 insertions(+) diff --git a/pgsql/pc_inout.c b/pgsql/pc_inout.c index 9eafc480..0b41b656 100644 --- a/pgsql/pc_inout.c +++ b/pgsql/pc_inout.c @@ -13,6 +13,7 @@ /* In/out functions */ Datum pcpoint_in(PG_FUNCTION_ARGS); +Datum pcpoint_in_bytea(PG_FUNCTION_ARGS); Datum pcpoint_out(PG_FUNCTION_ARGS); Datum pcpatch_in(PG_FUNCTION_ARGS); Datum pcpatch_out(PG_FUNCTION_ARGS); @@ -88,6 +89,33 @@ Datum pcpoint_in(PG_FUNCTION_ARGS) else PG_RETURN_NULL(); } + +PG_FUNCTION_INFO_V1(pcpoint_in_bytea); +Datum pcpoint_in_bytea(PG_FUNCTION_ARGS) +{ + bytea *bytes = PG_GETARG_BYTEA_P(0); + size_t wkblen = VARSIZE(bytes) - VARHDRSZ; + uint8 *wkb = VARDATA(bytes); + + SERIALIZED_POINT *serpt = NULL; + + /* non-Hex-encoded binary */ + + PCPOINT *pt; + PCSCHEMA *schema; + uint32 pcid; + pcid = pc_wkb_get_pcid(wkb); + schema = pc_schema_from_pcid(pcid, fcinfo); + pt = pc_point_from_wkb(schema, wkb, wkblen); + + pcid_consistent(pt->schema->pcid, pcid); + serpt = pc_point_serialize(pt); + pc_point_free(pt); + + if ( serpt ) PG_RETURN_POINTER(serpt); + else PG_RETURN_NULL(); +} + PG_FUNCTION_INFO_V1(pcpoint_out); Datum pcpoint_out(PG_FUNCTION_ARGS) { diff --git a/pgsql/pointcloud.sql.in b/pgsql/pointcloud.sql.in index d0a1d788..b2464a4b 100644 --- a/pgsql/pointcloud.sql.in +++ b/pgsql/pointcloud.sql.in @@ -186,6 +186,16 @@ CREATE OR REPLACE FUNCTION pcpoint_in(cstring) RETURNS pcpoint AS 'MODULE_PATHNAME', 'pcpoint_in' LANGUAGE 'c' IMMUTABLE STRICT; + +CREATE OR REPLACE FUNCTION pcpoint_in(internal) + RETURNS pcpoint AS 'MODULE_PATHNAME', 'pcpoint_in_bytea' + LANGUAGE 'c' IMMUTABLE STRICT; + + +CREATE OR REPLACE FUNCTION pcpoint_in(bytea) + RETURNS pcpoint AS 'MODULE_PATHNAME', 'pcpoint_in_bytea' + LANGUAGE 'c' IMMUTABLE STRICT; + CREATE OR REPLACE FUNCTION pcpoint_out(pcpoint) RETURNS cstring AS 'MODULE_PATHNAME', 'pcpoint_out' LANGUAGE 'c' IMMUTABLE STRICT; @@ -225,6 +235,9 @@ CREATE OR REPLACE FUNCTION PC_AsBinary(p pcpoint) RETURNS bytea AS 'MODULE_PATHNAME', 'pcpoint_as_bytea' LANGUAGE 'c' IMMUTABLE STRICT; +CREATE CAST (bytea as pcpoint) WITH FUNCTION pcpoint_in(bytea) AS ASSIGNMENT; + + ------------------------------------------------------------------- -- PCPATCH ------------------------------------------------------------------- From d503ba2b605d68739ac3ab7b22f3178fffe968d9 Mon Sep 17 00:00:00 2001 From: The Alchemist Date: Sat, 26 May 2018 23:59:40 -0400 Subject: [PATCH 2/2] delay the receive function stuff --- pgsql/pointcloud.sql.in | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pgsql/pointcloud.sql.in b/pgsql/pointcloud.sql.in index b2464a4b..3c91f5b5 100644 --- a/pgsql/pointcloud.sql.in +++ b/pgsql/pointcloud.sql.in @@ -186,12 +186,6 @@ CREATE OR REPLACE FUNCTION pcpoint_in(cstring) RETURNS pcpoint AS 'MODULE_PATHNAME', 'pcpoint_in' LANGUAGE 'c' IMMUTABLE STRICT; - -CREATE OR REPLACE FUNCTION pcpoint_in(internal) - RETURNS pcpoint AS 'MODULE_PATHNAME', 'pcpoint_in_bytea' - LANGUAGE 'c' IMMUTABLE STRICT; - - CREATE OR REPLACE FUNCTION pcpoint_in(bytea) RETURNS pcpoint AS 'MODULE_PATHNAME', 'pcpoint_in_bytea' LANGUAGE 'c' IMMUTABLE STRICT;