static SERIALIZED_PATCH * pc_patch_dimensional_serialize(const PCPATCH *patch_in) { int i; uint8_t *buf; size_t serpch_size = pc_patch_serialized_size(patch_in); SERIALIZED_PATCH *serpch = pcalloc(serpch_size); const PCPATCH_DIMENSIONAL *patch = (PCPATCH_DIMENSIONAL*)patch_in; assert(patch_in); assert(patch_in->type == PC_DIMENSIONAL); /* Copy basics */ serpch->pcid = patch->schema->pcid; serpch->npoints = patch->npoints; serpch->xmin = patch->xmin; serpch->ymin = patch->ymin; serpch->xmax = patch->xmax; serpch->ymax = patch->ymax; /* Copy byte buffers, one by one */ buf = serpch->data; for ( i = 0; i < patch->schema->ndims; i++ ) { size_t bsize = 0; PCBYTES *pcb = &(patch->bytes[i]); pc_bytes_serialize(pcb, buf, &bsize); buf += bsize; } SET_VARSIZE(serpch, serpch_size); return serpch; }
static SERIALIZED_PATCH * pc_patch_dimensional_serialize(const PCPATCH *patch_in) { // uint32_t size; // uint32_t pcid; // uint32_t compression; // uint32_t npoints; // double xmin, xmax, ymin, ymax; // data: // pcpoint[3] stats; // serialized_pcbytes[ndims] dimensions; int i; uint8_t *buf; size_t serpch_size = pc_patch_serialized_size(patch_in); SERIALIZED_PATCH *serpch = pcalloc(serpch_size); const PCPATCH_DIMENSIONAL *patch = (PCPATCH_DIMENSIONAL*)patch_in; assert(patch_in); assert(patch_in->type == PC_DIMENSIONAL); /* Copy basics */ serpch->pcid = patch->schema->pcid; serpch->npoints = patch->npoints; serpch->bounds = patch->bounds; serpch->compression = patch->type; //pcinfo(" dim serialisation : just copied basic : pcid : %d, npoints : %d, compression :%d, bounds\n", serpch->pcid,serpch->npoints,serpch->compression ); /* Get a pointer to the data area */ buf = serpch->data; /* Write stats into the buffer */ if ( patch->stats ) { buf += pc_patch_stats_serialize(buf, patch->schema, patch->stats); } else { pcerror("%s: stats missing!", __func__); } /* Write each dimension in after the stats */ for ( i = 0; i < patch->schema->ndims; i++ ) { size_t bsize = 0; PCBYTES *pcb = &(patch->bytes[i]); pc_bytes_serialize(pcb, buf, &bsize); buf += bsize; } SET_VARSIZE(serpch, serpch_size); return serpch; }
uint8_t * pc_patch_dimensional_to_wkb(const PCPATCH_DIMENSIONAL *patch, size_t *wkbsize) { /* byte: endianness (1 = NDR, 0 = XDR) uint32: pcid (key to POINTCLOUD_SCHEMAS) uint32: compression (0 = no compression, 1 = dimensional, 2 = GHT) uint32: npoints dimensions[]: pcbytes (interpret relative to pcid and compressions) */ int ndims = patch->schema->ndims; int i; uint8_t *buf; char endian = machine_endian(); /* endian + pcid + compression + npoints + datasize */ size_t size = 1 + 4 + 4 + 4 + pc_patch_dimensional_serialized_size(patch); uint8_t *wkb = pcalloc(size); uint32_t compression = patch->type; uint32_t npoints = patch->npoints; uint32_t pcid = patch->schema->pcid; wkb[0] = endian; /* Write endian flag */ memcpy(wkb + 1, &pcid, 4); /* Write PCID */ memcpy(wkb + 5, &compression, 4); /* Write compression */ memcpy(wkb + 9, &npoints, 4); /* Write npoints */ buf = wkb + 13; for ( i = 0; i < ndims; i++ ) { size_t bsz; PCBYTES *pcb = &(patch->bytes[i]); // XXX printf("pcb->(size=%d, interp=%d, npoints=%d, compression=%d, readonly=%d)\n",pcb->size, pcb->interpretation, pcb->npoints, pcb->compression, pcb->readonly); pc_bytes_serialize(pcb, buf, &bsz); buf += bsz; } if ( wkbsize ) *wkbsize = size; return wkb; }