------------------------------------------------------------------------- * datumSerialize * * Serialize a possibly-NULL datum into caller-provided storage. * * Note: "expanded" objects are flattened so as to produce a self-contained * representation, but other sorts of toast pointers are transferred as-is. * This is because the intended use of this function is to pass the value * to anoth
| 459 | *------------------------------------------------------------------------- |
| 460 | */ |
| 461 | void |
| 462 | datumSerialize(Datum value, bool isnull, bool typByVal, int typLen, |
| 463 | char **start_address) |
| 464 | { |
| 465 | ExpandedObjectHeader *eoh = NULL; |
| 466 | int header; |
| 467 | |
| 468 | /* Write header word. */ |
| 469 | if (isnull) |
| 470 | header = -2; |
| 471 | else if (typByVal) |
| 472 | header = -1; |
| 473 | else if (typLen == -1 && |
| 474 | VARATT_IS_EXTERNAL_EXPANDED(DatumGetPointer(value))) |
| 475 | { |
| 476 | eoh = DatumGetEOHP(value); |
| 477 | header = EOH_get_flat_size(eoh); |
| 478 | } |
| 479 | else |
| 480 | header = datumGetSize(value, typByVal, typLen); |
| 481 | memcpy(*start_address, &header, sizeof(int)); |
| 482 | *start_address += sizeof(int); |
| 483 | |
| 484 | /* If not null, write payload bytes. */ |
| 485 | if (!isnull) |
| 486 | { |
| 487 | if (typByVal) |
| 488 | { |
| 489 | memcpy(*start_address, &value, sizeof(Datum)); |
| 490 | *start_address += sizeof(Datum); |
| 491 | } |
| 492 | else if (eoh) |
| 493 | { |
| 494 | char *tmp; |
| 495 | |
| 496 | /* |
| 497 | * EOH_flatten_into expects the target address to be maxaligned, |
| 498 | * so we can't store directly to *start_address. |
| 499 | */ |
| 500 | tmp = (char *) palloc(header); |
| 501 | EOH_flatten_into(eoh, (void *) tmp, header); |
| 502 | memcpy(*start_address, tmp, header); |
| 503 | *start_address += header; |
| 504 | |
| 505 | /* be tidy. */ |
| 506 | pfree(tmp); |
| 507 | } |
| 508 | else |
| 509 | { |
| 510 | memcpy(*start_address, DatumGetPointer(value), header); |
| 511 | *start_address += header; |
| 512 | } |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | /*------------------------------------------------------------------------- |
| 517 | * datumRestore |
no test coverage detected