Fixed more issues with binary I/O
This commit is contained in:
parent
7148fdb94e
commit
4c6cd64194
|
@ -159,26 +159,39 @@ extern "C" {
|
||||||
phone_number_recv(PG_FUNCTION_ARGS) {
|
phone_number_recv(PG_FUNCTION_ARGS) {
|
||||||
try {
|
try {
|
||||||
StringInfo buf = (StringInfo)PG_GETARG_POINTER(0);
|
StringInfo buf = (StringInfo)PG_GETARG_POINTER(0);
|
||||||
ShortPhoneNumber* result;
|
ShortPhoneNumber* number;
|
||||||
|
|
||||||
result = (ShortPhoneNumber*)palloc(sizeof(ShortPhoneNumber));
|
number = (ShortPhoneNumber*)palloc(sizeof(ShortPhoneNumber));
|
||||||
//TODO: make portable.
|
//TODO: make portable (fix endianness issues, etc.).
|
||||||
*result = reinterpret_cast<ShortPhoneNumber>pq_getmsgint64(buf);
|
pq_copymsgbytes(buf, (char*)number, sizeof(ShortPhoneNumber));
|
||||||
PG_RETURN_POINTER(result);
|
PG_RETURN_POINTER(number);
|
||||||
|
} catch(const std::bad_alloc& e) {
|
||||||
|
reportOutOfMemory();
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
reportGenericError(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
PG_RETURN_NULL();
|
||||||
}
|
}
|
||||||
|
|
||||||
PGDLLEXPORT PG_FUNCTION_INFO_V1(phone_number_send);
|
PGDLLEXPORT PG_FUNCTION_INFO_V1(phone_number_send);
|
||||||
|
|
||||||
PGDLLEXPORT
|
PGDLLEXPORT
|
||||||
Datum
|
Datum
|
||||||
phone_number_send(PG_FUNCTION_ARGS)
|
phone_number_send(PG_FUNCTION_ARGS) {
|
||||||
{
|
try {
|
||||||
ShortPhoneNumber *number = (ShortPhoneNumber*)PG_GETARG_POINTER(0);
|
const ShortPhoneNumber *number = (ShortPhoneNumber*)PG_GETARG_POINTER(0);
|
||||||
StringInfoData buf;
|
StringInfoData buf;
|
||||||
|
|
||||||
pq_begintypsend(&buf);
|
pq_begintypsend(&buf);
|
||||||
//TODO: make portable.
|
pq_sendbytes(&buf, (const char*)number, sizeof(ShortPhoneNumber));
|
||||||
pq_sendint64(&buf, reinterpret_cast<uint64>*number);;
|
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
|
||||||
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
|
} catch(const std::bad_alloc& e) {
|
||||||
|
reportOutOfMemory();
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
reportGenericError(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
PG_RETURN_NULL();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue