Changed binary I/O functions (still not portable)

This commit is contained in:
BLM 2015-07-22 14:32:52 -05:00
parent 5080bf839e
commit 7148fdb94e
1 changed files with 11 additions and 14 deletions

View File

@ -154,20 +154,17 @@ extern "C" {
PGDLLEXPORT PG_FUNCTION_INFO_V1(phone_number_recv); PGDLLEXPORT PG_FUNCTION_INFO_V1(phone_number_recv);
//TODO: handle leading zeroes?
//TODO: implement these correctly.
PGDLLEXPORT PGDLLEXPORT
Datum Datum
phone_number_recv(PG_FUNCTION_ARGS) phone_number_recv(PG_FUNCTION_ARGS) {
{ try {
StringInfo buf = (StringInfo)PG_GETARG_POINTER(0); StringInfo buf = (StringInfo)PG_GETARG_POINTER(0);
PhoneNumber *result; ShortPhoneNumber* result;
//TODO: error handling? result = (ShortPhoneNumber*)palloc(sizeof(ShortPhoneNumber));
result = (PhoneNumber*)palloc0(sizeof(PhoneNumber)); //TODO: make portable.
result->set_country_code(pq_getmsgint(buf, 4)); *result = reinterpret_cast<ShortPhoneNumber>pq_getmsgint64(buf);
result->set_national_number(pq_getmsgint64(buf)); PG_RETURN_POINTER(result);
PG_RETURN_POINTER(result);
} }
PGDLLEXPORT PG_FUNCTION_INFO_V1(phone_number_send); PGDLLEXPORT PG_FUNCTION_INFO_V1(phone_number_send);
@ -176,12 +173,12 @@ extern "C" {
Datum Datum
phone_number_send(PG_FUNCTION_ARGS) phone_number_send(PG_FUNCTION_ARGS)
{ {
PhoneNumber *number = (PhoneNumber*)PG_GETARG_POINTER(0); ShortPhoneNumber *number = (ShortPhoneNumber*)PG_GETARG_POINTER(0);
StringInfoData buf; StringInfoData buf;
pq_begintypsend(&buf); pq_begintypsend(&buf);
pq_sendint(&buf, number->country_code(), 4); //TODO: make portable.
pq_sendint64(&buf, number->national_number()); pq_sendint64(&buf, reinterpret_cast<uint64>*number);;
PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
} }
} }