Pg: Add perl2bin() and bin2perl() conversion methods

This commit is contained in:
Yorhel 2025-04-30 17:07:44 +02:00
parent af9340f908
commit beeefcf337
4 changed files with 69 additions and 2 deletions

View file

@ -626,3 +626,30 @@ static void fupg_tio_free(fupg_tio *tio) {
safefree(tio->record.tio);
}
}
static SV *fupg_perl2bin(pTHX_ fupg_conn *conn, Oid oid, SV *sv) {
int refresh_done = 0;
fupg_tio tio;
fustr buf;
memset(&tio, 0, sizeof(tio));
fupg_tio_setup(aTHX_ conn, &tio, FUPGT_SEND, oid, &refresh_done);
fustr_init(&buf, sv_newmortal(), SIZE_MAX);
tio.send(aTHX_ &tio, sv, &buf); /* XXX: Leaks 'tio' on error */
fupg_tio_free(&tio);
return fustr_done(&buf);
}
static SV *fupg_bin2perl(pTHX_ fupg_conn *conn, Oid oid, SV *sv) {
int refresh_done = 0;
fupg_tio tio;
STRLEN len;
const char *buf = SvPVbyte(sv, len);
memset(&tio, 0, sizeof(tio));
fupg_tio_setup(aTHX_ conn, &tio, FUPGT_RECV, oid, &refresh_done);
SV *r = tio.recv(aTHX_ &tio, buf, len); /* XXX: Leaks 'tio' on error */
fupg_tio_free(&tio);
return r;
}