MCPcopy Create free account
hub / github.com/apache/cloudberry / ReadArrayBinary

Function ReadArrayBinary

src/backend/utils/adt/arrayfuncs.c:1456–1553  ·  view source on GitHub ↗

* ReadArrayBinary: * collect the data elements of an array being read in binary style. * * Inputs: * buf: the data buffer to read from. * nitems: total number of array elements (already read). * receiveproc: type-specific receive procedure for element datatype. * typioparam, typmod: auxiliary values to pass to receiveproc. * typlen, typbyval, typalign: storage parameters of element dataty

Source from the content-addressed store, hash-verified

1454 * nitems elements.
1455 */
1456static void
1457ReadArrayBinary(StringInfo buf,
1458 int nitems,
1459 FmgrInfo *receiveproc,
1460 Oid typioparam,
1461 int32 typmod,
1462 int typlen,
1463 bool typbyval,
1464 char typalign,
1465 Datum *values,
1466 bool *nulls,
1467 bool *hasnulls,
1468 int32 *nbytes)
1469{
1470 int i;
1471 bool hasnull;
1472 int32 totbytes;
1473
1474 for (i = 0; i < nitems; i++)
1475 {
1476 int itemlen;
1477 StringInfoData elem_buf;
1478 char csave;
1479
1480 /* Get and check the item length */
1481 itemlen = pq_getmsgint(buf, 4);
1482 if (itemlen < -1 || itemlen > (buf->len - buf->cursor))
1483 ereport(ERROR,
1484 (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
1485 errmsg("insufficient data left in message")));
1486
1487 if (itemlen == -1)
1488 {
1489 /* -1 length means NULL */
1490 values[i] = ReceiveFunctionCall(receiveproc, NULL,
1491 typioparam, typmod);
1492 nulls[i] = true;
1493 continue;
1494 }
1495
1496 /*
1497 * Rather than copying data around, we just set up a phony StringInfo
1498 * pointing to the correct portion of the input buffer. We assume we
1499 * can scribble on the input buffer so as to maintain the convention
1500 * that StringInfos have a trailing null.
1501 */
1502 elem_buf.data = &buf->data[buf->cursor];
1503 elem_buf.maxlen = itemlen + 1;
1504 elem_buf.len = itemlen;
1505 elem_buf.cursor = 0;
1506
1507 buf->cursor += itemlen;
1508
1509 csave = buf->data[buf->cursor];
1510 buf->data[buf->cursor] = '\0';
1511
1512 /* Now call the element's receiveproc */
1513 values[i] = ReceiveFunctionCall(receiveproc, &elem_buf,

Callers 1

array_recvFunction · 0.85

Calls 4

pq_getmsgintFunction · 0.85
ReceiveFunctionCallFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected