/* * Write an uncompressed patch out to hex */ static void test_patch_hex_out() { // 00 endian // 00000000 pcid // 00000000 compression // 00000002 npoints // 0000000200000003000000050006 pt1 (XYZi) // 0000000200000003000000050008 pt2 (XYZi) static char *wkt_result = "{\"pcid\":0,\"pts\":[[0.02,0.03,0.05,6],[0.02,0.03,0.05,8]]}"; static char *hexresult_xdr = "0000000000000000000000000200000002000000030000000500060000000200000003000000050008"; static char *hexresult_ndr = "0100000000000000000200000002000000030000000500000006000200000003000000050000000800"; double d0[4] = { 0.02, 0.03, 0.05, 6 }; double d1[4] = { 0.02, 0.03, 0.05, 8 }; PCPOINT *pt0 = pc_point_from_double_array(simpleschema, d0, 4); PCPOINT *pt1 = pc_point_from_double_array(simpleschema, d1, 4); PCPATCH_UNCOMPRESSED *pa; uint8_t *wkb; size_t wkbsize; char *hexwkb; char *wkt; PCPOINTLIST *pl = pc_pointlist_make(2); pc_pointlist_add_point(pl, pt0); pc_pointlist_add_point(pl, pt1); pa = pc_patch_uncompressed_from_pointlist(pl); wkb = pc_patch_uncompressed_to_wkb(pa, &wkbsize); // printf("wkbsize %zu\n", wkbsize); hexwkb = hexbytes_from_bytes(wkb, wkbsize); // printf("hexwkb %s\n", hexwkb); // printf("hexresult_ndr %s\n", hexresult_ndr); // printf("machine_endian %d\n", machine_endian()); if ( machine_endian() == PC_NDR ) { CU_ASSERT_STRING_EQUAL(hexwkb, hexresult_ndr); } else { CU_ASSERT_STRING_EQUAL(hexwkb, hexresult_xdr); } wkt = pc_patch_uncompressed_to_string(pa); // printf("wkt %s\n", wkt); CU_ASSERT_STRING_EQUAL(wkt, wkt_result); pc_patch_free((PCPATCH*)pa); pc_pointlist_free(pl); pcfree(hexwkb); pcfree(wkb); pcfree(wkt); }
Datum pcpoint_from_double_array(PG_FUNCTION_ARGS) { uint32 pcid = PG_GETARG_INT32(0); ArrayType *arrptr = PG_GETARG_ARRAYTYPE_P(1); int nelems; float8 *vals; PCPOINT *pt; PCSCHEMA *schema = pc_schema_from_pcid(pcid, fcinfo); SERIALIZED_POINT *serpt; if ( ! schema ) elog(ERROR, "unable to load schema for pcid = %d", pcid); if ( ARR_ELEMTYPE(arrptr) != FLOAT8OID ) elog(ERROR, "array must be of float8[]"); if ( ARR_NDIM(arrptr) != 1 ) elog(ERROR, "float8[] must have only one dimension"); if ( ARR_HASNULL(arrptr) ) elog(ERROR, "float8[] must not have null elements"); nelems = ARR_DIMS(arrptr)[0]; if ( nelems != schema->ndims || ARR_LBOUND(arrptr)[0] > 1 ) elog(ERROR, "array dimensions do not match schema dimensions of pcid = %d", pcid); vals = (float8*) ARR_DATA_PTR(arrptr); pt = pc_point_from_double_array(schema, vals, nelems); serpt = pc_point_serialize(pt); pc_point_free(pt); PG_RETURN_POINTER(serpt); }