mirror of
https://github.com/pgpointcloud/pointcloud.git
synced 2025-12-08 20:36:04 +00:00
Tie hexkbw handling to in/out functions
This commit is contained in:
parent
1a2093da57
commit
f1ecbb08e4
@ -222,7 +222,7 @@ uint32_t pc_schema_is_valid(const PCSCHEMA *s);
|
||||
/** Create a new PCPOINT */
|
||||
PCPOINT* pc_point_make(const PCSCHEMA *s);
|
||||
/** Create a new readonly PCPOINT on top of a data buffer */
|
||||
PCPOINT* pc_point_from_data(const PCSCHEMA *s, uint8_t *data);
|
||||
PCPOINT* pc_point_from_data(const PCSCHEMA *s, const uint8_t *data);
|
||||
/** Create a new read/write PCPOINT on top of a data buffer */
|
||||
PCPOINT* pc_point_from_data_rw(const PCSCHEMA *s, uint8_t *data);
|
||||
/** Create a new read/write PCPOINT from a double array */
|
||||
|
||||
@ -42,7 +42,7 @@ pc_point_make(const PCSCHEMA *s)
|
||||
};
|
||||
|
||||
PCPOINT *
|
||||
pc_point_from_data(const PCSCHEMA *s, uint8_t *data)
|
||||
pc_point_from_data(const PCSCHEMA *s, const uint8_t *data)
|
||||
{
|
||||
size_t sz;
|
||||
PCPOINT *pt;
|
||||
@ -56,7 +56,7 @@ pc_point_from_data(const PCSCHEMA *s, uint8_t *data)
|
||||
|
||||
/* Reference the external data */
|
||||
pt = pcalloc(sizeof(PCPOINT));
|
||||
pt->data = data;
|
||||
pt->data = (uint8_t*)data;
|
||||
|
||||
/* Set up basic info */
|
||||
pt->schema = s;
|
||||
|
||||
@ -27,7 +27,7 @@ Datum pcpoint_in(PG_FUNCTION_ARGS)
|
||||
/* Empty string. */
|
||||
if ( str[0] == '\0' )
|
||||
{
|
||||
ereport(ERROR,(errmsg("parse error - invalid pcpoint")));
|
||||
ereport(ERROR,(errmsg("pcpoint parse error - empty string")));
|
||||
}
|
||||
|
||||
/* Binary or text form? Let's find out. */
|
||||
@ -46,6 +46,22 @@ Datum pcpoint_in(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_POINTER(serpt);
|
||||
}
|
||||
|
||||
PG_FUNCTION_INFO_V1(pcpoint_out);
|
||||
Datum pcpoint_out(PG_FUNCTION_ARGS)
|
||||
{
|
||||
PCPOINT *pcpt = NULL;
|
||||
SERIALIZED_POINT *serpt = NULL;
|
||||
uint8_t *wkb = NULL;
|
||||
size_t wkb_size = 0;
|
||||
char *hexwkb = NULL;
|
||||
|
||||
serpt = (SERIALIZED_POINT*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
|
||||
pcpt = pc_point_deserialize(serpt);
|
||||
wkb = wkb_from_point(pcpt, &wkb_size);
|
||||
hexwkb = hexbytes_from_bytes(wkb, wkb_size);
|
||||
PG_RETURN_CSTRING(hexwkb);
|
||||
}
|
||||
|
||||
|
||||
PG_FUNCTION_INFO_V1(PC_SchemaIsValid);
|
||||
Datum PC_SchemaIsValid(PG_FUNCTION_ARGS)
|
||||
|
||||
@ -379,7 +379,7 @@ pc_schema_get_by_id(uint32_t pcid)
|
||||
*/
|
||||
|
||||
SERIALIZED_POINT *
|
||||
pc_point_serialize(PCPOINT *pcpt)
|
||||
pc_point_serialize(const PCPOINT *pcpt)
|
||||
{
|
||||
size_t serpt_size = sizeof(SERIALIZED_POINT) - 1 + pcpt->schema->size;
|
||||
SERIALIZED_POINT *serpt = palloc(serpt_size);
|
||||
@ -389,3 +389,13 @@ pc_point_serialize(PCPOINT *pcpt)
|
||||
return serpt;
|
||||
}
|
||||
|
||||
PCPOINT *
|
||||
pc_point_deserialize(const SERIALIZED_POINT *serpt)
|
||||
{
|
||||
PCPOINT *pcpt;
|
||||
PCSCHEMA *schema = pc_schema_get_by_id(serpt->pcid);
|
||||
pcpt = pc_point_from_data(schema, serpt->data);
|
||||
return pcpt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -36,10 +36,10 @@ SERIALIZED_PATCH;
|
||||
PCSCHEMA* pc_schema_get_by_id(uint32_t pcid);
|
||||
|
||||
/** Turn a PCPOINT into a byte buffer suitable for saving in PgSQL */
|
||||
SERIALIZED_POINT* pc_point_serialize(PCPOINT *pcpt);
|
||||
SERIALIZED_POINT* pc_point_serialize(const PCPOINT *pcpt);
|
||||
|
||||
/** Turn a byte buffer into a PCPOINT for processing */
|
||||
PCPOINT* pc_point_deserialize(SERIALIZED_POINT *serpt);
|
||||
PCPOINT* pc_point_deserialize(const SERIALIZED_POINT *serpt);
|
||||
|
||||
/** Returns 1 for little (NDR) and 0 for big (XDR) */
|
||||
char machine_endian(void);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user