From 5594ad04ef4d6b8c30dfde2d86a1ad595737b453 Mon Sep 17 00:00:00 2001 From: Xavier Stevens Date: Tue, 20 Jan 2015 15:23:45 -0800 Subject: [PATCH] Fixing styling using clang-format --- proto/pg_logicaldec.proto | 4 +-- src/decoderbufs.c | 69 ++++++++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/proto/pg_logicaldec.proto b/proto/pg_logicaldec.proto index 39cd277..dc17724 100644 --- a/proto/pg_logicaldec.proto +++ b/proto/pg_logicaldec.proto @@ -11,8 +11,8 @@ enum Op { } message Point { - required double x = 1; - required double y = 2; + required double x = 1; + required double y = 2; } message DatumMessage { diff --git a/src/decoderbufs.c b/src/decoderbufs.c index 0461001..93183f9 100644 --- a/src/decoderbufs.c +++ b/src/decoderbufs.c @@ -24,11 +24,11 @@ */ #if defined(__linux__) - #include +#include #elif defined(__APPLE__) - #include - #include - #define htobe64(x) OSSwapHostToBigInt64(x) +#include +#include +#define htobe64(x) OSSwapHostToBigInt64(x) #endif #include @@ -91,8 +91,7 @@ static void pg_decode_commit_txn(LogicalDecodingContext *ctx, static void pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, Relation rel, ReorderBufferChange *change); -void _PG_init(void) { -} +void _PG_init(void) {} /* specify output plugin callbacks */ void _PG_output_plugin_init(OutputPluginCallbacks *cb) { @@ -148,21 +147,34 @@ static void pg_decode_startup(LogicalDecodingContext *ctx, char *geom_oid_str = NULL; char *geog_oid_str = NULL; if (SPI_connect() == SPI_ERROR_CONNECT) { - elog(NOTICE, "Could not connect to SPI manager to scan for PostGIS types"); + elog(NOTICE, + "Could not connect to SPI manager to scan for PostGIS types"); SPI_finish(); return; } - if (SPI_OK_SELECT == SPI_execute("SELECT oid FROM pg_type WHERE typname = 'geometry'", true, 1) && SPI_processed > 0) { - geom_oid_str = SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1); + if (SPI_OK_SELECT == + SPI_execute("SELECT oid FROM pg_type WHERE typname = 'geometry'", + true, 1) && + SPI_processed > 0) { + geom_oid_str = + SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1); if (geom_oid_str != NULL) { - fprintf(stderr, "Decoderbufs detected PostGIS geometry type with oid: %s\n", geom_oid_str); + fprintf(stderr, + "Decoderbufs detected PostGIS geometry type with oid: %s\n", + geom_oid_str); geometry_oid = atoi(geom_oid_str); } } - if (SPI_OK_SELECT == SPI_execute("SELECT oid FROM pg_type WHERE typname = 'geography'", true, 1) && SPI_processed > 0) { - geog_oid_str = SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1); + if (SPI_OK_SELECT == + SPI_execute("SELECT oid FROM pg_type WHERE typname = 'geography'", + true, 1) && + SPI_processed > 0) { + geog_oid_str = + SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1); if (geog_oid_str != NULL) { - fprintf(stderr, "Decoderbufs detected PostGIS geography type with oid: %s\n", geog_oid_str); + fprintf(stderr, + "Decoderbufs detected PostGIS geography type with oid: %s\n", + geog_oid_str); geography_oid = atoi(geog_oid_str); } } @@ -180,8 +192,7 @@ static void pg_decode_shutdown(LogicalDecodingContext *ctx) { /* BEGIN callback */ static void pg_decode_begin_txn(LogicalDecodingContext *ctx, - ReorderBufferTXN *txn) { -} + ReorderBufferTXN *txn) {} /* COMMIT callback */ static void pg_decode_commit_txn(LogicalDecodingContext *ctx, @@ -268,13 +279,18 @@ static void print_tuple_msg(StringInfo out, Decoderbufs__DatumMessage **tup, appendStringInfo(out, ", datum[%s]", dmsg->datum_string); break; case POINTOID: - appendStringInfo(out, ", datum[POINT(%f, %f)]", dmsg->datum_point->x, dmsg->datum_point->y); + appendStringInfo(out, ", datum[POINT(%f, %f)]", + dmsg->datum_point->x, dmsg->datum_point->y); break; default: - if (dmsg->column_type == geometry_oid && dmsg->datum_point != NULL) { - appendStringInfo(out, ", datum[GEOMETRY(POINT(%f,%f))]", dmsg->datum_point->x, dmsg->datum_point->y); - } else if (dmsg->column_type == geography_oid && dmsg->datum_point != NULL) { - appendStringInfo(out, ", datum[GEOGRAPHY(POINT(%f,%f))]", dmsg->datum_point->x, dmsg->datum_point->y); + if (dmsg->column_type == geometry_oid && + dmsg->datum_point != NULL) { + appendStringInfo(out, ", datum[GEOMETRY(POINT(%f,%f))]", + dmsg->datum_point->x, dmsg->datum_point->y); + } else if (dmsg->column_type == geography_oid && + dmsg->datum_point != NULL) { + appendStringInfo(out, ", datum[GEOGRAPHY(POINT(%f,%f))]", + dmsg->datum_point->x, dmsg->datum_point->y); } break; } @@ -307,13 +323,14 @@ static double numeric_to_double_no_overflow(Numeric num) { return val; } -static bool geography_point_as_decoderbufs_point(Datum datum, Decoderbufs__Point *p) { +static bool geography_point_as_decoderbufs_point(Datum datum, + Decoderbufs__Point *p) { GSERIALIZED *geom; LWGEOM *lwgeom; LWPOINT *point = NULL; POINT2D p2d; - geom = (GSERIALIZED*)PG_DETOAST_DATUM(datum); + geom = (GSERIALIZED *)PG_DETOAST_DATUM(datum); if (gserialized_get_type(geom) != POINTTYPE) { return false; } @@ -386,9 +403,9 @@ static void set_datum_value(Decoderbufs__DatumMessage *datum_msg, Oid typid, datum_msg->datum_string = pnstrdup(output, strlen(output)); break; case TIMESTAMPOID: - /* - * THIS FALLTHROUGH IS MAKING THE ASSUMPTION WE ARE ON UTC - */ + /* + * THIS FALLTHROUGH IS MAKING THE ASSUMPTION WE ARE ON UTC + */ case TIMESTAMPTZOID: output = timestamptz_to_str(DatumGetTimestampTz(datum)); datum_msg->datum_string = pnstrdup(output, strlen(output)); @@ -585,7 +602,7 @@ static void pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, size_t ssize = decoderbufs__row_message__pack(&rmsg, packed); uint64_t flen = htobe64(ssize); /* frame encoding size */ - appendBinaryStringInfo(ctx->out, (char *) &flen, sizeof(flen)); + appendBinaryStringInfo(ctx->out, (char *)&flen, sizeof(flen)); /* frame encoding payload */ appendBinaryStringInfo(ctx->out, packed, ssize); OutputPluginWrite(ctx, true);