int pqt_put_point(PGtypeArgs *args) { unsigned int *buf; PGpoint *pt = va_arg(args->ap, PGpoint *); PUTNULLCHK(args, pt); buf = (unsigned int *) args->put.out; pqt_swap8(buf, &pt->x, 1); pqt_swap8(buf + 2, &pt->y, 1); return 16; }
int pqt_put_circle(PGtypeArgs *args) { unsigned int *buf; PGcircle *circle = va_arg(args->ap, PGcircle *); PUTNULLCHK(args, circle); buf = (unsigned int *) args->put.out; pqt_swap8(buf, &circle->center.x, 1); pqt_swap8(buf + 2, &circle->center.y, 1); pqt_swap8(buf + 4, &circle->radius, 1); return 24; }
int pqt_put_lseg(PGtypeArgs *args) { unsigned int *buf; PGlseg *lseg = va_arg(args->ap, PGlseg *); PUTNULLCHK(args, lseg); buf = (unsigned int *) args->put.out; pqt_swap8(buf, &lseg->pts[0].x, 1); pqt_swap8(buf + 2, &lseg->pts[0].y, 1); pqt_swap8(buf + 4, &lseg->pts[1].x, 1); pqt_swap8(buf + 6, &lseg->pts[1].y, 1); return 32; }
int pqt_put_box(PGtypeArgs *args) { unsigned int *buf; PGbox *box = va_arg(args->ap, PGbox *); PUTNULLCHK(args, box); buf = (unsigned int *) args->put.out; pqt_swap8(buf, &box->high.x, 1); pqt_swap8(buf + 2, &box->high.y, 1); pqt_swap8(buf + 4, &box->low.x, 1); pqt_swap8(buf + 6, &box->low.y, 1); return 32; }
/* handles cidr as well */ int pqt_put_inet(PGtypeArgs *args) { unsigned char *b = (unsigned char *)args->put.out; PGinet *inet = va_arg(args->ap, PGinet *); int family; PUTNULLCHK(args, inet); family = ((struct sockaddr *)inet->sa_buf)->sa_family; if (family == AF_INET) { struct sockaddr_in *sa = (struct sockaddr_in *) inet->sa_buf; *b++ = (unsigned char) PGSQL_AF_INET; *b++ = (unsigned char) inet->mask; *b++ = (unsigned char) (inet->is_cidr ? 1 : 0); *b++ = (unsigned char) 4; memcpy(b, &sa->sin_addr, 4); b += 4; } #ifdef AF_INET6 else if (family == AF_INET6) { struct sockaddr_in6 *sa = (struct sockaddr_in6 *) inet->sa_buf; *b++ = (unsigned char) PGSQL_AF_INET6; *b++ = (unsigned char) inet->mask; *b++ = (unsigned char) (inet->is_cidr ? 1 : 0); *b++ = (unsigned char) 16; memcpy(b, &sa->sin6_addr, 16); b += 16; } #endif else { return args->errorf(args, "Unknown inet address family %d", family); } return (int) ((char *) b - args->put.out); }
int pqt_put_array(PGtypeArgs *args) { int i; int hasnull=0; int ndims; int nitems; int arrsize; char *out; int lbound[MAXDIM]; int dims[MAXDIM]; PGarray *arr = va_arg(args->ap, PGarray *); PUTNULLCHK(args, arr); if (arr->ndims < 0) return args->errorf(args, "arr.ndims is invalid - %d", arr->ndims); /* auto configure when ndims is 0 to 1d array */ if (arr->ndims == 0) { ndims = 1; dims[0] = arr->param->vcnt; lbound[0] = 1; } else { ndims = arr->ndims; memcpy(lbound, arr->lbound, sizeof(lbound)); memcpy(dims, arr->dims, sizeof(dims)); } nitems = 1; for (i=0; i < ndims; i++) nitems *= dims[i]; /* make sure array is on the same page as the param */ if (nitems != arr->param->vcnt) return args->errorf(args, "param element count %d is different than array's %d", arr->param->vcnt, nitems); /* header: ndims + hasnull + elemtype + ((dims + lbound) * ndims) */ arrsize = 4 + 4 + 4 + (8 * ndims); /* compute data length, also get the hasnull flag */ for (i=0; i < arr->param->vcnt; i++) { if (arr->param->vals[i].format == 0) return args->errorf(args, "Cannot put array elements in text format"); arrsize += 4; if (arr->param->vals[i].datal == NULL_LEN) hasnull = 1; else arrsize += arr->param->vals[i].datal; } /* make sure args->put.out is large enough */ if (args->put.expandBuffer(args, arrsize) == -1) return -1; out = args->put.out; /* number od dimensions */ pqt_buf_putint4(out, ndims); out += 4; /* array hasnull flag */ pqt_buf_putint4(out, hasnull); out += 4; /* array element oid */ pqt_buf_putint4(out, args->typhandler->typoid); out += 4; /* dims and lbound */ for (i=0; i < ndims; i++) { pqt_buf_putint4(out, dims[i]); out += 4; pqt_buf_putint4(out, lbound[i]); out += 4; } /* write the element lengths and data */ for (i=0; i < arr->param->vcnt; i++) { pqt_buf_putint4(out, arr->param->vals[i].datal); out += 4; if (arr->param->vals[i].datal > 0) { memcpy(out, arr->param->vals[i].data, arr->param->vals[i].datal); out += arr->param->vals[i].datal; } } return arrsize; }