PostgreSQL Source Code  git master
pqformat.h File Reference
#include "lib/stringinfo.h"
#include "mb/pg_wchar.h"
#include "port/pg_bswap.h"
Include dependency graph for pqformat.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void pq_beginmessage (StringInfo buf, char msgtype)
 
void pq_beginmessage_reuse (StringInfo buf, char msgtype)
 
void pq_endmessage (StringInfo buf)
 
void pq_endmessage_reuse (StringInfo buf)
 
void pq_sendbytes (StringInfo buf, const char *data, int datalen)
 
void pq_sendcountedtext (StringInfo buf, const char *str, int slen, bool countincludesself)
 
void pq_sendtext (StringInfo buf, const char *str, int slen)
 
void pq_sendstring (StringInfo buf, const char *str)
 
void pq_send_ascii_string (StringInfo buf, const char *str)
 
void pq_sendfloat4 (StringInfo buf, float4 f)
 
void pq_sendfloat8 (StringInfo buf, float8 f)
 
static void pq_writeint8 (StringInfoData *pg_restrict buf, int8 i)
 
static void pq_writeint16 (StringInfoData *pg_restrict buf, int16 i)
 
static void pq_writeint32 (StringInfoData *pg_restrict buf, int32 i)
 
static void pq_writeint64 (StringInfoData *pg_restrict buf, int64 i)
 
static void pq_writestring (StringInfoData *pg_restrict buf, const char *pg_restrict str)
 
static void pq_sendint8 (StringInfo buf, int8 i)
 
static void pq_sendint16 (StringInfo buf, int16 i)
 
static void pq_sendint32 (StringInfo buf, int32 i)
 
static void pq_sendint64 (StringInfo buf, int64 i)
 
static void pq_sendbyte (StringInfo buf, int8 byt)
 
static void pq_sendint (StringInfo buf, int i, int b)
 
void pq_begintypsend (StringInfo buf)
 
byteapq_endtypsend (StringInfo buf)
 
void pq_puttextmessage (char msgtype, const char *str)
 
void pq_putemptymessage (char msgtype)
 
int pq_getmsgbyte (StringInfo msg)
 
unsigned int pq_getmsgint (StringInfo msg, int b)
 
int64 pq_getmsgint64 (StringInfo msg)
 
float4 pq_getmsgfloat4 (StringInfo msg)
 
float8 pq_getmsgfloat8 (StringInfo msg)
 
const char * pq_getmsgbytes (StringInfo msg, int datalen)
 
void pq_copymsgbytes (StringInfo msg, char *buf, int datalen)
 
char * pq_getmsgtext (StringInfo msg, int rawbytes, int *nbytes)
 
const char * pq_getmsgstring (StringInfo msg)
 
const char * pq_getmsgrawstring (StringInfo msg)
 
void pq_getmsgend (StringInfo msg)
 

Function Documentation

◆ pq_beginmessage()

void pq_beginmessage ( StringInfo  buf,
char  msgtype 
)

Definition at line 87 of file pqformat.c.

References StringInfoData::cursor, and initStringInfo().

Referenced by NotifyMyFrontEnd(), ParallelWorkerMain(), perform_base_backup(), PostgresMain(), printsimple(), printsimple_startup(), ReadyForQuery(), ReceiveCopyBegin(), ReportGUCOption(), send_message_to_frontend(), sendAuthRequest(), SendBackupHeader(), SendCopyBegin(), SendFunctionResult(), SendNegotiateProtocolVersion(), SendTimeLineHistory(), SendXlogRecPtrResult(), StartLogicalReplication(), and StartReplication().

88 {
89  initStringInfo(buf);
90 
91  /*
92  * We stash the message type into the buffer's cursor field, expecting
93  * that the pq_sendXXX routines won't touch it. We could alternatively
94  * make it the first byte of the buffer contents, but this seems easier.
95  */
96  buf->cursor = msgtype;
97 }
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46

◆ pq_beginmessage_reuse()

void pq_beginmessage_reuse ( StringInfo  buf,
char  msgtype 
)

Definition at line 108 of file pqformat.c.

References StringInfoData::cursor, and resetStringInfo().

Referenced by exec_describe_statement_message(), printtup(), printtup_20(), printtup_internal_20(), and SendRowDescriptionMessage().

109 {
110  resetStringInfo(buf);
111 
112  /*
113  * We stash the message type into the buffer's cursor field, expecting
114  * that the pq_sendXXX routines won't touch it. We could alternatively
115  * make it the first byte of the buffer contents, but this seems easier.
116  */
117  buf->cursor = msgtype;
118 }
void resetStringInfo(StringInfo str)
Definition: stringinfo.c:62

◆ pq_begintypsend()

◆ pq_copymsgbytes()

void pq_copymsgbytes ( StringInfo  msg,
char *  buf,
int  datalen 
)

Definition at line 530 of file pqformat.c.

References StringInfoData::cursor, StringInfoData::data, ereport, errcode(), errmsg(), ERROR, and StringInfoData::len.

Referenced by bit_recv(), bytearecv(), CopyGetData(), logicalrep_read_tuple(), pq_getmsgint(), pq_getmsgint64(), pq_sendint(), and varbit_recv().

531 {
532  if (datalen < 0 || datalen > (msg->len - msg->cursor))
533  ereport(ERROR,
534  (errcode(ERRCODE_PROTOCOL_VIOLATION),
535  errmsg("insufficient data left in message")));
536  memcpy(buf, &msg->data[msg->cursor], datalen);
537  msg->cursor += datalen;
538 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:67
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ pq_endmessage()

void pq_endmessage ( StringInfo  buf)

Definition at line 298 of file pqformat.c.

References StringInfoData::cursor, StringInfoData::data, StringInfoData::len, pfree(), and pq_putmessage.

Referenced by HandleParallelMessage(), NotifyMyFrontEnd(), ParallelWorkerMain(), perform_base_backup(), PostgresMain(), printsimple(), printsimple_startup(), ReadyForQuery(), ReceiveCopyBegin(), ReportGUCOption(), send_message_to_frontend(), sendAuthRequest(), SendBackupHeader(), SendCopyBegin(), SendFunctionResult(), SendNegotiateProtocolVersion(), SendTimeLineHistory(), SendXlogRecPtrResult(), StartLogicalReplication(), and StartReplication().

299 {
300  /* msgtype was saved in cursor field */
301  (void) pq_putmessage(buf->cursor, buf->data, buf->len);
302  /* no need to complain about any failure, since pqcomm.c already did */
303  pfree(buf->data);
304  buf->data = NULL;
305 }
void pfree(void *pointer)
Definition: mcxt.c:936
#define pq_putmessage(msgtype, s, len)
Definition: libpq.h:42

◆ pq_endmessage_reuse()

void pq_endmessage_reuse ( StringInfo  buf)

Definition at line 316 of file pqformat.c.

References StringInfoData::cursor, StringInfoData::data, StringInfoData::len, and pq_putmessage.

Referenced by exec_describe_statement_message(), printtup(), printtup_20(), printtup_internal_20(), and SendRowDescriptionMessage().

317 {
318  /* msgtype was saved in cursor field */
319  (void) pq_putmessage(buf->cursor, buf->data, buf->len);
320 }
#define pq_putmessage(msgtype, s, len)
Definition: libpq.h:42

◆ pq_endtypsend()

bytea* pq_endtypsend ( StringInfo  buf)

Definition at line 348 of file pqformat.c.

References Assert, StringInfoData::data, StringInfoData::len, SET_VARSIZE, and VARHDRSZ.

Referenced by abstimesend(), array_send(), boolsend(), box_send(), cash_send(), charsend(), cidsend(), circle_send(), complex_send(), cstring_send(), date_send(), enum_send(), float4send(), float8send(), hstore_send(), int2send(), int4send(), int8_avg_serialize(), int8send(), interval_send(), json_send(), jsonb_send(), line_send(), lseg_send(), macaddr8_send(), macaddr_send(), namesend(), network_send(), numeric_avg_serialize(), numeric_poly_serialize(), numeric_send(), numeric_serialize(), oidsend(), path_send(), pg_lsn_send(), point_send(), poly_send(), pq_sendint(), range_send(), record_send(), reltimesend(), textsend(), tidsend(), time_send(), timestamp_send(), timestamptz_send(), timetz_send(), tintervalsend(), tsquerysend(), tsvectorsend(), txid_snapshot_send(), unknownsend(), uuid_send(), varbit_send(), void_send(), xidsend(), and xml_send().

349 {
350  bytea *result = (bytea *) buf->data;
351 
352  /* Insert correct length into bytea length word */
353  Assert(buf->len >= VARHDRSZ);
354  SET_VARSIZE(result, buf->len);
355 
356  return result;
357 }
#define VARHDRSZ
Definition: c.h:503
#define Assert(condition)
Definition: c.h:680
Definition: c.h:497
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328

◆ pq_getmsgbyte()

int pq_getmsgbyte ( StringInfo  msg)

Definition at line 401 of file pqformat.c.

References StringInfoData::cursor, StringInfoData::data, ereport, errcode(), errmsg(), ERROR, and StringInfoData::len.

Referenced by apply_dispatch(), boolrecv(), charrecv(), HandleParallelMessage(), logicalrep_read_attrs(), logicalrep_read_commit(), logicalrep_read_delete(), logicalrep_read_insert(), logicalrep_read_rel(), logicalrep_read_tuple(), logicalrep_read_update(), LogicalRepApplyLoop(), macaddr8_recv(), macaddr_recv(), network_recv(), path_recv(), PostgresMain(), pq_parse_errornotice(), pq_sendint(), ProcessStandbyMessage(), ProcessStandbyReplyMessage(), range_recv(), and XLogWalRcvProcessMsg().

402 {
403  if (msg->cursor >= msg->len)
404  ereport(ERROR,
405  (errcode(ERRCODE_PROTOCOL_VIOLATION),
406  errmsg("no data left in message")));
407  return (unsigned char) msg->data[msg->cursor++];
408 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ pq_getmsgbytes()

const char* pq_getmsgbytes ( StringInfo  msg,
int  datalen 
)

Definition at line 510 of file pqformat.c.

References StringInfoData::cursor, StringInfoData::data, ereport, errcode(), errmsg(), ERROR, and StringInfoData::len.

Referenced by CheckSCRAMAuth(), exec_bind_message(), parse_fcall_arguments(), parse_fcall_arguments_20(), pq_sendint(), range_recv(), uuid_recv(), and xml_recv().

511 {
512  const char *result;
513 
514  if (datalen < 0 || datalen > (msg->len - msg->cursor))
515  ereport(ERROR,
516  (errcode(ERRCODE_PROTOCOL_VIOLATION),
517  errmsg("insufficient data left in message")));
518  result = &msg->data[msg->cursor];
519  msg->cursor += datalen;
520  return result;
521 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ pq_getmsgend()

void pq_getmsgend ( StringInfo  msg)

Definition at line 637 of file pqformat.c.

References StringInfoData::cursor, ereport, errcode(), errmsg(), ERROR, and StringInfoData::len.

Referenced by CheckSCRAMAuth(), exec_bind_message(), HandleFunctionRequest(), HandleParallelMessage(), int8_avg_deserialize(), numeric_avg_deserialize(), numeric_deserialize(), numeric_poly_deserialize(), PostgresMain(), pq_parse_errornotice(), pq_sendint(), and range_recv().

638 {
639  if (msg->cursor != msg->len)
640  ereport(ERROR,
641  (errcode(ERRCODE_PROTOCOL_VIOLATION),
642  errmsg("invalid message format")));
643 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ pq_getmsgfloat4()

float4 pq_getmsgfloat4 ( StringInfo  msg)

Definition at line 471 of file pqformat.c.

References i, pq_getmsgint(), and swap.

Referenced by float4recv(), and pq_sendint().

472 {
473  union
474  {
475  float4 f;
476  uint32 i;
477  } swap;
478 
479  swap.i = pq_getmsgint(msg, 4);
480  return swap.f;
481 }
#define swap(a, b)
Definition: qsort.c:94
unsigned int uint32
Definition: c.h:306
float float4
Definition: c.h:438
int i
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417

◆ pq_getmsgfloat8()

float8 pq_getmsgfloat8 ( StringInfo  msg)

Definition at line 490 of file pqformat.c.

References i, pq_getmsgint64(), and swap.

Referenced by box_recv(), circle_recv(), complex_recv(), float8recv(), line_recv(), lseg_recv(), path_recv(), point_recv(), poly_recv(), and pq_sendint().

491 {
492  union
493  {
494  float8 f;
495  int64 i;
496  } swap;
497 
498  swap.i = pq_getmsgint64(msg);
499  return swap.f;
500 }
#define swap(a, b)
Definition: qsort.c:94
double float8
Definition: c.h:439
int i
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455

◆ pq_getmsgint()

unsigned int pq_getmsgint ( StringInfo  msg,
int  b 
)

Definition at line 417 of file pqformat.c.

References elog, ERROR, pg_ntoh16, pg_ntoh32, and pq_copymsgbytes().

Referenced by abstimerecv(), array_recv(), bit_recv(), CheckSCRAMAuth(), cidrecv(), date_recv(), exec_bind_message(), HandleFunctionRequest(), HandleParallelMessage(), hstore_recv(), int2recv(), int4recv(), interval_recv(), jsonb_recv(), logicalrep_read_attrs(), logicalrep_read_begin(), logicalrep_read_delete(), logicalrep_read_insert(), logicalrep_read_rel(), logicalrep_read_tuple(), logicalrep_read_typ(), logicalrep_read_update(), numeric_avg_deserialize(), numeric_deserialize(), numeric_recv(), oidrecv(), parse_fcall_arguments(), parse_fcall_arguments_20(), path_recv(), poly_recv(), PostgresMain(), pq_getmsgfloat4(), pq_sendint(), ProcessStandbyHSFeedbackMessage(), range_recv(), ReadArrayBinary(), record_recv(), reltimerecv(), tidrecv(), timetz_recv(), tintervalrecv(), tsqueryrecv(), tsvectorrecv(), txid_snapshot_recv(), varbit_recv(), and xidrecv().

418 {
419  unsigned int result;
420  unsigned char n8;
421  uint16 n16;
422  uint32 n32;
423 
424  switch (b)
425  {
426  case 1:
427  pq_copymsgbytes(msg, (char *) &n8, 1);
428  result = n8;
429  break;
430  case 2:
431  pq_copymsgbytes(msg, (char *) &n16, 2);
432  result = pg_ntoh16(n16);
433  break;
434  case 4:
435  pq_copymsgbytes(msg, (char *) &n32, 4);
436  result = pg_ntoh32(n32);
437  break;
438  default:
439  elog(ERROR, "unsupported integer size %d", b);
440  result = 0; /* keep compiler quiet */
441  break;
442  }
443  return result;
444 }
#define pg_ntoh16(x)
Definition: pg_bswap.h:124
unsigned short uint16
Definition: c.h:305
#define pg_ntoh32(x)
Definition: pg_bswap.h:125
#define ERROR
Definition: elog.h:43
unsigned int uint32
Definition: c.h:306
void pq_copymsgbytes(StringInfo msg, char *buf, int datalen)
Definition: pqformat.c:530
#define elog
Definition: elog.h:219

◆ pq_getmsgint64()

◆ pq_getmsgrawstring()

const char* pq_getmsgrawstring ( StringInfo  msg)

Definition at line 610 of file pqformat.c.

References StringInfoData::cursor, StringInfoData::data, ereport, errcode(), errmsg(), ERROR, StringInfoData::len, and generate_unaccent_rules::str.

Referenced by CheckSCRAMAuth(), HandleParallelMessage(), pq_parse_errornotice(), and pq_sendint().

611 {
612  char *str;
613  int slen;
614 
615  str = &msg->data[msg->cursor];
616 
617  /*
618  * It's safe to use strlen() here because a StringInfo is guaranteed to
619  * have a trailing null byte. But check we found a null inside the
620  * message.
621  */
622  slen = strlen(str);
623  if (msg->cursor + slen >= msg->len)
624  ereport(ERROR,
625  (errcode(ERRCODE_PROTOCOL_VIOLATION),
626  errmsg("invalid string in message")));
627  msg->cursor += slen + 1;
628 
629  return str;
630 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ pq_getmsgstring()

const char* pq_getmsgstring ( StringInfo  msg)

Definition at line 581 of file pqformat.c.

References StringInfoData::cursor, StringInfoData::data, ereport, errcode(), errmsg(), ERROR, StringInfoData::len, pg_client_to_server(), and generate_unaccent_rules::str.

Referenced by CopyGetData(), exec_bind_message(), HandleFunctionRequest(), logicalrep_read_attrs(), logicalrep_read_namespace(), logicalrep_read_origin(), logicalrep_read_rel(), logicalrep_read_typ(), PostgresMain(), pq_sendint(), tsqueryrecv(), and tsvectorrecv().

582 {
583  char *str;
584  int slen;
585 
586  str = &msg->data[msg->cursor];
587 
588  /*
589  * It's safe to use strlen() here because a StringInfo is guaranteed to
590  * have a trailing null byte. But check we found a null inside the
591  * message.
592  */
593  slen = strlen(str);
594  if (msg->cursor + slen >= msg->len)
595  ereport(ERROR,
596  (errcode(ERRCODE_PROTOCOL_VIOLATION),
597  errmsg("invalid string in message")));
598  msg->cursor += slen + 1;
599 
600  return pg_client_to_server(str, slen);
601 }
int errcode(int sqlerrcode)
Definition: elog.c:575
char * pg_client_to_server(const char *s, int len)
Definition: mbutils.c:545
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ pq_getmsgtext()

char* pq_getmsgtext ( StringInfo  msg,
int  rawbytes,
int *  nbytes 
)

Definition at line 548 of file pqformat.c.

References StringInfoData::cursor, StringInfoData::data, ereport, errcode(), errmsg(), ERROR, StringInfoData::len, palloc(), pg_client_to_server(), and generate_unaccent_rules::str.

Referenced by bpcharrecv(), cstring_recv(), enum_recv(), hstore_recv(), json_recv(), jsonb_recv(), namerecv(), pq_sendint(), textrecv(), unknownrecv(), and varcharrecv().

549 {
550  char *str;
551  char *p;
552 
553  if (rawbytes < 0 || rawbytes > (msg->len - msg->cursor))
554  ereport(ERROR,
555  (errcode(ERRCODE_PROTOCOL_VIOLATION),
556  errmsg("insufficient data left in message")));
557  str = &msg->data[msg->cursor];
558  msg->cursor += rawbytes;
559 
560  p = pg_client_to_server(str, rawbytes);
561  if (p != str) /* actual conversion has been done? */
562  *nbytes = strlen(p);
563  else
564  {
565  p = (char *) palloc(rawbytes + 1);
566  memcpy(p, str, rawbytes);
567  p[rawbytes] = '\0';
568  *nbytes = rawbytes;
569  }
570  return p;
571 }
int errcode(int sqlerrcode)
Definition: elog.c:575
char * pg_client_to_server(const char *s, int len)
Definition: mbutils.c:545
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
void * palloc(Size size)
Definition: mcxt.c:835
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ pq_putemptymessage()

void pq_putemptymessage ( char  msgtype)

◆ pq_puttextmessage()

void pq_puttextmessage ( char  msgtype,
const char *  str 
)

Definition at line 369 of file pqformat.c.

References pfree(), pg_server_to_client(), and pq_putmessage.

Referenced by pq_sendint(), printtup_startup(), SendBackupHeader(), SendXlogRecPtrResult(), and StartReplication().

370 {
371  int slen = strlen(str);
372  char *p;
373 
374  p = pg_server_to_client(str, slen);
375  if (p != str) /* actual conversion has been done? */
376  {
377  (void) pq_putmessage(msgtype, p, strlen(p) + 1);
378  pfree(p);
379  return;
380  }
381  (void) pq_putmessage(msgtype, str, slen + 1);
382 }
char * pg_server_to_client(const char *s, int len)
Definition: mbutils.c:623
void pfree(void *pointer)
Definition: mcxt.c:936
#define pq_putmessage(msgtype, s, len)
Definition: libpq.h:42

◆ pq_send_ascii_string()

void pq_send_ascii_string ( StringInfo  buf,
const char *  str 
)

Definition at line 229 of file pqformat.c.

References appendStringInfoChar(), appendStringInfoCharMacro, and IS_HIGHBIT_SET.

Referenced by err_sendstring().

230 {
231  while (*str)
232  {
233  char ch = *str++;
234 
235  if (IS_HIGHBIT_SET(ch))
236  ch = '?';
237  appendStringInfoCharMacro(buf, ch);
238  }
239  appendStringInfoChar(buf, '\0');
240 }
#define appendStringInfoCharMacro(str, ch)
Definition: stringinfo.h:127
#define IS_HIGHBIT_SET(ch)
Definition: c.h:949
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:169

◆ pq_sendbyte()

◆ pq_sendbytes()

void pq_sendbytes ( StringInfo  buf,
const char *  data,
int  datalen 
)

Definition at line 125 of file pqformat.c.

References appendBinaryStringInfo().

Referenced by array_send(), int8_avg_serialize(), numeric_avg_serialize(), numeric_poly_serialize(), numeric_serialize(), printtup(), printtup_internal_20(), range_send(), record_send(), send_int8_string(), sendAuthRequest(), SendBackupHeader(), SendFunctionResult(), SendTimeLineHistory(), SendXlogRecPtrResult(), uuid_send(), and varbit_send().

126 {
127  /* use variant that maintains a trailing null-byte, out of caution */
128  appendBinaryStringInfo(buf, data, datalen);
129 }
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:208

◆ pq_sendcountedtext()

void pq_sendcountedtext ( StringInfo  buf,
const char *  str,
int  slen,
bool  countincludesself 
)

Definition at line 142 of file pqformat.c.

References appendBinaryStringInfoNT(), pfree(), pg_server_to_client(), and pq_sendint32().

Referenced by logicalrep_write_tuple(), printsimple(), printtup(), printtup_20(), and SendFunctionResult().

144 {
145  int extra = countincludesself ? 4 : 0;
146  char *p;
147 
148  p = pg_server_to_client(str, slen);
149  if (p != str) /* actual conversion has been done? */
150  {
151  slen = strlen(p);
152  pq_sendint32(buf, slen + extra);
153  appendBinaryStringInfoNT(buf, p, slen);
154  pfree(p);
155  }
156  else
157  {
158  pq_sendint32(buf, slen + extra);
159  appendBinaryStringInfoNT(buf, str, slen);
160  }
161 }
static void pq_sendint32(StringInfo buf, int32 i)
Definition: pqformat.h:148
char * pg_server_to_client(const char *s, int len)
Definition: mbutils.c:623
void pfree(void *pointer)
Definition: mcxt.c:936
void appendBinaryStringInfoNT(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:234

◆ pq_sendfloat4()

void pq_sendfloat4 ( StringInfo  buf,
float4  f 
)

Definition at line 254 of file pqformat.c.

References i, pq_sendint32(), and swap.

Referenced by float4send().

255 {
256  union
257  {
258  float4 f;
259  uint32 i;
260  } swap;
261 
262  swap.f = f;
263  pq_sendint32(buf, swap.i);
264 }
#define swap(a, b)
Definition: qsort.c:94
static void pq_sendint32(StringInfo buf, int32 i)
Definition: pqformat.h:148
unsigned int uint32
Definition: c.h:306
float float4
Definition: c.h:438
int i

◆ pq_sendfloat8()

void pq_sendfloat8 ( StringInfo  buf,
float8  f 
)

Definition at line 278 of file pqformat.c.

References i, pq_sendint64(), and swap.

Referenced by box_send(), circle_send(), complex_send(), float8send(), line_send(), lseg_send(), path_send(), point_send(), and poly_send().

279 {
280  union
281  {
282  float8 f;
283  int64 i;
284  } swap;
285 
286  swap.f = f;
287  pq_sendint64(buf, swap.i);
288 }
#define swap(a, b)
Definition: qsort.c:94
static void pq_sendint64(StringInfo buf, int64 i)
Definition: pqformat.h:156
double float8
Definition: c.h:439
int i

◆ pq_sendint()

static void pq_sendint ( StringInfo  buf,
int  i,
int  b 
)
inlinestatic

Definition at line 175 of file pqformat.h.

References buf, elog, ERROR, pq_begintypsend(), pq_copymsgbytes(), pq_endtypsend(), pq_getmsgbyte(), pq_getmsgbytes(), pq_getmsgend(), pq_getmsgfloat4(), pq_getmsgfloat8(), pq_getmsgint(), pq_getmsgint64(), pq_getmsgrawstring(), pq_getmsgstring(), pq_getmsgtext(), pq_putemptymessage(), pq_puttextmessage(), pq_sendint16(), pq_sendint32(), pq_sendint8(), and generate_unaccent_rules::str.

176 {
177  switch (b)
178  {
179  case 1:
180  pq_sendint8(buf, (int8) i);
181  break;
182  case 2:
183  pq_sendint16(buf, (int16) i);
184  break;
185  case 4:
186  pq_sendint32(buf, (int32) i);
187  break;
188  default:
189  elog(ERROR, "unsupported integer size %d", b);
190  break;
191  }
192 }
signed short int16
Definition: c.h:293
static void pq_sendint32(StringInfo buf, int32 i)
Definition: pqformat.h:148
static void pq_sendint8(StringInfo buf, int8 i)
Definition: pqformat.h:132
signed int int32
Definition: c.h:294
#define ERROR
Definition: elog.h:43
signed char int8
Definition: c.h:292
static void pq_sendint16(StringInfo buf, int16 i)
Definition: pqformat.h:140
int i
#define elog
Definition: elog.h:219

◆ pq_sendint16()

static void pq_sendint16 ( StringInfo  buf,
int16  i 
)
inlinestatic

◆ pq_sendint32()

static void pq_sendint32 ( StringInfo  buf,
int32  i 
)
inlinestatic

◆ pq_sendint64()

◆ pq_sendint8()

static void pq_sendint8 ( StringInfo  buf,
int8  i 
)
inlinestatic

Definition at line 132 of file pqformat.h.

References enlargeStringInfo(), and pq_writeint8().

Referenced by jsonb_send(), pq_sendbyte(), pq_sendint(), printtup_20(), printtup_internal_20(), and tsquerysend().

133 {
134  enlargeStringInfo(buf, sizeof(int8));
135  pq_writeint8(buf, i);
136 }
void enlargeStringInfo(StringInfo str, int needed)
Definition: stringinfo.c:264
signed char int8
Definition: c.h:292
static void pq_writeint8(StringInfoData *pg_restrict buf, int8 i)
Definition: pqformat.h:50
int i

◆ pq_sendstring()

void pq_sendstring ( StringInfo  buf,
const char *  str 
)

Definition at line 197 of file pqformat.c.

References appendBinaryStringInfoNT(), pfree(), and pg_server_to_client().

Referenced by err_sendstring(), logicalrep_write_attrs(), logicalrep_write_namespace(), logicalrep_write_origin(), logicalrep_write_rel(), logicalrep_write_typ(), NotifyMyFrontEnd(), printsimple_startup(), ReportGUCOption(), SendBackupHeader(), SendNegotiateProtocolVersion(), SendRowDescriptionCols_2(), SendTimeLineHistory(), SendXlogRecPtrResult(), and tsquerysend().

198 {
199  int slen = strlen(str);
200  char *p;
201 
202  p = pg_server_to_client(str, slen);
203  if (p != str) /* actual conversion has been done? */
204  {
205  slen = strlen(p);
206  appendBinaryStringInfoNT(buf, p, slen + 1);
207  pfree(p);
208  }
209  else
210  appendBinaryStringInfoNT(buf, str, slen + 1);
211 }
char * pg_server_to_client(const char *s, int len)
Definition: mbutils.c:623
void pfree(void *pointer)
Definition: mcxt.c:936
void appendBinaryStringInfoNT(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:234

◆ pq_sendtext()

void pq_sendtext ( StringInfo  buf,
const char *  str,
int  slen 
)

Definition at line 174 of file pqformat.c.

References appendBinaryStringInfo(), pfree(), and pg_server_to_client().

Referenced by cstring_send(), enum_send(), hstore_send(), json_send(), jsonb_send(), namesend(), textsend(), tsvectorsend(), unknownsend(), and xml_send().

175 {
176  char *p;
177 
178  p = pg_server_to_client(str, slen);
179  if (p != str) /* actual conversion has been done? */
180  {
181  slen = strlen(p);
182  appendBinaryStringInfo(buf, p, slen);
183  pfree(p);
184  }
185  else
186  appendBinaryStringInfo(buf, str, slen);
187 }
char * pg_server_to_client(const char *s, int len)
Definition: mbutils.c:623
void pfree(void *pointer)
Definition: mcxt.c:936
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:208

◆ pq_writeint16()

static void pq_writeint16 ( StringInfoData *pg_restrict  buf,
int16  i 
)
inlinestatic

Definition at line 64 of file pqformat.h.

References Assert, and pg_hton16.

Referenced by pq_sendint16(), and SendRowDescriptionCols_3().

65 {
66  int16 ni = pg_hton16(i);
67 
68  Assert(buf->len + (int) sizeof(int16) <= buf->maxlen);
69  memcpy((char *pg_restrict) (buf->data + buf->len), &ni, sizeof(int16));
70  buf->len += sizeof(int16);
71 }
signed short int16
Definition: c.h:293
#define pg_hton16(x)
Definition: pg_bswap.h:120
#define Assert(condition)
Definition: c.h:680
int i

◆ pq_writeint32()

static void pq_writeint32 ( StringInfoData *pg_restrict  buf,
int32  i 
)
inlinestatic

Definition at line 78 of file pqformat.h.

References Assert, and pg_hton32.

Referenced by pq_sendint32(), and SendRowDescriptionCols_3().

79 {
80  int32 ni = pg_hton32(i);
81 
82  Assert(buf->len + (int) sizeof(int32) <= buf->maxlen);
83  memcpy((char *pg_restrict) (buf->data + buf->len), &ni, sizeof(int32));
84  buf->len += sizeof(int32);
85 }
signed int int32
Definition: c.h:294
#define pg_hton32(x)
Definition: pg_bswap.h:121
#define Assert(condition)
Definition: c.h:680
int i

◆ pq_writeint64()

static void pq_writeint64 ( StringInfoData *pg_restrict  buf,
int64  i 
)
inlinestatic

Definition at line 92 of file pqformat.h.

References Assert, and pg_hton64.

Referenced by pq_sendint64().

93 {
94  int64 ni = pg_hton64(i);
95 
96  Assert(buf->len + (int) sizeof(int64) <= buf->maxlen);
97  memcpy((char *pg_restrict) (buf->data + buf->len), &ni, sizeof(int64));
98  buf->len += sizeof(int64);
99 }
#define pg_hton64(x)
Definition: pg_bswap.h:122
#define Assert(condition)
Definition: c.h:680
int i

◆ pq_writeint8()

static void pq_writeint8 ( StringInfoData *pg_restrict  buf,
int8  i 
)
inlinestatic

Definition at line 50 of file pqformat.h.

References Assert, and i.

Referenced by pq_sendint8().

51 {
52  int8 ni = i;
53 
54  Assert(buf->len + (int) sizeof(int8) <= buf->maxlen);
55  memcpy((char *pg_restrict) (buf->data + buf->len), &ni, sizeof(int8));
56  buf->len += sizeof(int8);
57 }
signed char int8
Definition: c.h:292
#define Assert(condition)
Definition: c.h:680
int i

◆ pq_writestring()

static void pq_writestring ( StringInfoData *pg_restrict  buf,
const char *pg_restrict  str 
)
inlinestatic

Definition at line 112 of file pqformat.h.

References Assert, pfree(), and pg_server_to_client().

Referenced by SendRowDescriptionCols_3().

113 {
114  int slen = strlen(str);
115  char *p;
116 
117  p = pg_server_to_client(str, slen);
118  if (p != str) /* actual conversion has been done? */
119  slen = strlen(p);
120 
121  Assert(buf->len + slen + 1 <= buf->maxlen);
122 
123  memcpy(((char *pg_restrict) buf->data + buf->len), p, slen + 1);
124  buf->len += slen + 1;
125 
126  if (p != str)
127  pfree(p);
128 }
char * pg_server_to_client(const char *s, int len)
Definition: mbutils.c:623
void pfree(void *pointer)
Definition: mcxt.c:936
#define Assert(condition)
Definition: c.h:680