From 30f609484d025bfb7c69f8f6b9610dc981cb5fb8 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 12 May 2003 23:08:52 +0000 Subject: Add binary I/O routines for a bunch more datatypes. Still a few to go, but that was enough tedium for one day. Along the way, move the few support routines for types xid and cid into a more logical place. --- src/backend/utils/adt/bool.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/backend/utils/adt/bool.c') diff --git a/src/backend/utils/adt/bool.c b/src/backend/utils/adt/bool.c index a2fb5b4fa23..ccc97683033 100644 --- a/src/backend/utils/adt/bool.c +++ b/src/backend/utils/adt/bool.c @@ -8,13 +8,14 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.26 2002/06/20 20:29:36 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.27 2003/05/12 23:08:50 tgl Exp $ * *------------------------------------------------------------------------- */ #include "postgres.h" +#include "libpq/pqformat.h" #include "utils/builtins.h" /***************************************************************************** @@ -94,6 +95,36 @@ boolout(PG_FUNCTION_ARGS) PG_RETURN_CSTRING(result); } +/* + * boolrecv - converts external binary format to bool + * + * The external representation is one byte. Any nonzero value is taken + * as "true". + */ +Datum +boolrecv(PG_FUNCTION_ARGS) +{ + StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); + int ext; + + ext = pq_getmsgbyte(buf); + PG_RETURN_BOOL((ext != 0) ? true : false); +} + +/* + * boolsend - converts bool to binary format + */ +Datum +boolsend(PG_FUNCTION_ARGS) +{ + bool arg1 = PG_GETARG_BOOL(0); + StringInfoData buf; + + pq_begintypsend(&buf); + pq_sendbyte(&buf, arg1 ? 1 : 0); + PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); +} + /***************************************************************************** * PUBLIC ROUTINES * -- cgit v1.2.3