LCOV - differential code coverage report
Current view: top level - src/include/libpq - pqformat.h (source / functions) Coverage Total Hit UBC GNC CBC DCB
Current: 7a15cff1f11193467898da1c1fabf06fd2caee04 vs 84a3778c79c2d28b4dc281d03ef2ab019b16483b Lines: 88.2 % 68 60 8 10 50 10
Current Date: 2025-12-15 18:36:29 -0500 Functions: 100.0 % 11 11 5 6 5
Baseline: lcov-20251216-010103-baseline Branches: 50.0 % 20 10 10 10
Baseline Date: 2025-12-15 13:30:48 -0800 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(30,360] days: 100.0 % 10 10 10
(360..) days: 86.2 % 58 50 8 50
Function coverage date bins:
(30,360] days: 100.0 % 5 5 5
(360..) days: 100.0 % 6 6 6
Branch coverage date bins:
(360..) days: 50.0 % 20 10 10 10

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * pqformat.h
                                  4                 :                :  *      Definitions for formatting and parsing frontend/backend messages
                                  5                 :                :  *
                                  6                 :                :  * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
                                  7                 :                :  * Portions Copyright (c) 1994, Regents of the University of California
                                  8                 :                :  *
                                  9                 :                :  * src/include/libpq/pqformat.h
                                 10                 :                :  *
                                 11                 :                :  *-------------------------------------------------------------------------
                                 12                 :                :  */
                                 13                 :                : #ifndef PQFORMAT_H
                                 14                 :                : #define PQFORMAT_H
                                 15                 :                : 
                                 16                 :                : #include "lib/stringinfo.h"
                                 17                 :                : #include "mb/pg_wchar.h"
                                 18                 :                : #include "port/pg_bswap.h"
                                 19                 :                : 
                                 20                 :                : extern void pq_beginmessage(StringInfo buf, char msgtype);
                                 21                 :                : extern void pq_beginmessage_reuse(StringInfo buf, char msgtype);
                                 22                 :                : extern void pq_endmessage(StringInfo buf);
                                 23                 :                : extern void pq_endmessage_reuse(StringInfo buf);
                                 24                 :                : 
                                 25                 :                : extern void pq_sendbytes(StringInfo buf, const void *data, int datalen);
                                 26                 :                : extern void pq_sendcountedtext(StringInfo buf, const char *str, int slen);
                                 27                 :                : extern void pq_sendtext(StringInfo buf, const char *str, int slen);
                                 28                 :                : extern void pq_sendstring(StringInfo buf, const char *str);
                                 29                 :                : extern void pq_send_ascii_string(StringInfo buf, const char *str);
                                 30                 :                : extern void pq_sendfloat4(StringInfo buf, float4 f);
                                 31                 :                : extern void pq_sendfloat8(StringInfo buf, float8 f);
                                 32                 :                : 
                                 33                 :                : /*
                                 34                 :                :  * Append a [u]int8 to a StringInfo buffer, which already has enough space
                                 35                 :                :  * preallocated.
                                 36                 :                :  *
                                 37                 :                :  * The use of restrict allows the compiler to optimize the code based on
                                 38                 :                :  * the assumption that buf, buf->len, buf->data and *buf->data don't
                                 39                 :                :  * overlap. Without the annotation buf->len etc cannot be kept in a register
                                 40                 :                :  * over subsequent pq_writeintN calls.
                                 41                 :                :  *
                                 42                 :                :  * The use of StringInfoData * rather than StringInfo is due to MSVC being
                                 43                 :                :  * overly picky and demanding a * before a restrict.
                                 44                 :                :  */
                                 45                 :                : static inline void
   48 peter@eisentraut.org       46                 :GNC     1883680 : pq_writeint8(StringInfoData *restrict buf, uint8 i)
                                 47                 :                : {
 2730 andres@anarazel.de         48                 :CBC     1883680 :     uint8       ni = i;
                                 49                 :                : 
                                 50         [ -  + ]:        1883680 :     Assert(buf->len + (int) sizeof(uint8) <= buf->maxlen);
   50 peter@eisentraut.org       51                 :GNC     1883680 :     memcpy(buf->data + buf->len, &ni, sizeof(uint8));
 2730 andres@anarazel.de         52                 :CBC     1883680 :     buf->len += sizeof(uint8);
 2988                            53                 :        1883680 : }
                                 54                 :                : 
                                 55                 :                : /*
                                 56                 :                :  * Append a [u]int16 to a StringInfo buffer, which already has enough space
                                 57                 :                :  * preallocated.
                                 58                 :                :  */
                                 59                 :                : static inline void
   48 peter@eisentraut.org       60                 :GNC     6024521 : pq_writeint16(StringInfoData *restrict buf, uint16 i)
                                 61                 :                : {
 2730 andres@anarazel.de         62                 :CBC     6024521 :     uint16      ni = pg_hton16(i);
                                 63                 :                : 
                                 64         [ -  + ]:        6024521 :     Assert(buf->len + (int) sizeof(uint16) <= buf->maxlen);
   50 peter@eisentraut.org       65                 :GNC     6024521 :     memcpy(buf->data + buf->len, &ni, sizeof(uint16));
 2730 andres@anarazel.de         66                 :CBC     6024521 :     buf->len += sizeof(uint16);
 2988                            67                 :        6024521 : }
                                 68                 :                : 
                                 69                 :                : /*
                                 70                 :                :  * Append a [u]int32 to a StringInfo buffer, which already has enough space
                                 71                 :                :  * preallocated.
                                 72                 :                :  */
                                 73                 :                : static inline void
   48 peter@eisentraut.org       74                 :GNC    20981893 : pq_writeint32(StringInfoData *restrict buf, uint32 i)
                                 75                 :                : {
 2730 andres@anarazel.de         76                 :CBC    20981893 :     uint32      ni = pg_hton32(i);
                                 77                 :                : 
                                 78         [ -  + ]:       20981893 :     Assert(buf->len + (int) sizeof(uint32) <= buf->maxlen);
   50 peter@eisentraut.org       79                 :GNC    20981893 :     memcpy(buf->data + buf->len, &ni, sizeof(uint32));
 2730 andres@anarazel.de         80                 :CBC    20981893 :     buf->len += sizeof(uint32);
 2988                            81                 :       20981893 : }
                                 82                 :                : 
                                 83                 :                : /*
                                 84                 :                :  * Append a [u]int64 to a StringInfo buffer, which already has enough space
                                 85                 :                :  * preallocated.
                                 86                 :                :  */
                                 87                 :                : static inline void
   48 peter@eisentraut.org       88                 :GNC     1575685 : pq_writeint64(StringInfoData *restrict buf, uint64 i)
                                 89                 :                : {
 2730 andres@anarazel.de         90                 :CBC     1575685 :     uint64      ni = pg_hton64(i);
                                 91                 :                : 
                                 92         [ -  + ]:        1575685 :     Assert(buf->len + (int) sizeof(uint64) <= buf->maxlen);
   50 peter@eisentraut.org       93                 :GNC     1575685 :     memcpy(buf->data + buf->len, &ni, sizeof(uint64));
 2730 andres@anarazel.de         94                 :CBC     1575685 :     buf->len += sizeof(uint64);
 2988                            95                 :        1575685 : }
                                 96                 :                : 
                                 97                 :                : /*
                                 98                 :                :  * Append a null-terminated text string (with conversion) to a buffer with
                                 99                 :                :  * preallocated space.
                                100                 :                :  *
                                101                 :                :  * NB: The pre-allocated space needs to be sufficient for the string after
                                102                 :                :  * converting to client encoding.
                                103                 :                :  *
                                104                 :                :  * NB: passed text string must be null-terminated, and so is the data
                                105                 :                :  * sent to the frontend.
                                106                 :                :  */
                                107                 :                : static inline void
   48 peter@eisentraut.org      108                 :GNC      514110 : pq_writestring(StringInfoData *restrict buf, const char *restrict str)
                                109                 :                : {
 2988 andres@anarazel.de        110                 :CBC      514110 :     int         slen = strlen(str);
                                111                 :                :     char       *p;
                                112                 :                : 
                                113                 :         514110 :     p = pg_server_to_client(str, slen);
                                114         [ +  + ]:         514110 :     if (p != str)               /* actual conversion has been done? */
                                115                 :             18 :         slen = strlen(p);
                                116                 :                : 
                                117         [ -  + ]:         514110 :     Assert(buf->len + slen + 1 <= buf->maxlen);
                                118                 :                : 
   50 peter@eisentraut.org      119                 :GNC      514110 :     memcpy(buf->data + buf->len, p, slen + 1);
 2988 andres@anarazel.de        120                 :CBC      514110 :     buf->len += slen + 1;
                                121                 :                : 
                                122         [ +  + ]:         514110 :     if (p != str)
                                123                 :             18 :         pfree(p);
                                124                 :         514110 : }
                                125                 :                : 
                                126                 :                : /* append a binary [u]int8 to a StringInfo buffer */
                                127                 :                : static inline void
 2730                           128                 :        1883680 : pq_sendint8(StringInfo buf, uint8 i)
                                129                 :                : {
                                130                 :        1883680 :     enlargeStringInfo(buf, sizeof(uint8));
 2988                           131                 :        1883680 :     pq_writeint8(buf, i);
                                132                 :        1883680 : }
                                133                 :                : 
                                134                 :                : /* append a binary [u]int16 to a StringInfo buffer */
                                135                 :                : static inline void
 2730                           136                 :        4482191 : pq_sendint16(StringInfo buf, uint16 i)
                                137                 :                : {
                                138                 :        4482191 :     enlargeStringInfo(buf, sizeof(uint16));
 2988                           139                 :        4482191 :     pq_writeint16(buf, i);
                                140                 :        4482191 : }
                                141                 :                : 
                                142                 :                : /* append a binary [u]int32 to a StringInfo buffer */
                                143                 :                : static inline void
 2730                           144                 :       19439563 : pq_sendint32(StringInfo buf, uint32 i)
                                145                 :                : {
                                146                 :       19439563 :     enlargeStringInfo(buf, sizeof(uint32));
 2988                           147                 :       19439563 :     pq_writeint32(buf, i);
                                148                 :       19439563 : }
                                149                 :                : 
                                150                 :                : /* append a binary [u]int64 to a StringInfo buffer */
                                151                 :                : static inline void
 2730                           152                 :        1575685 : pq_sendint64(StringInfo buf, uint64 i)
                                153                 :                : {
                                154                 :        1575685 :     enlargeStringInfo(buf, sizeof(uint64));
 2988                           155                 :        1575685 :     pq_writeint64(buf, i);
                                156                 :        1575685 : }
                                157                 :                : 
                                158                 :                : /* append a binary byte to a StringInfo buffer */
                                159                 :                : static inline void
 2730                           160                 :        1883664 : pq_sendbyte(StringInfo buf, uint8 byt)
                                161                 :                : {
 2988                           162                 :        1883664 :     pq_sendint8(buf, byt);
                                163                 :        1883664 : }
                                164                 :                : 
                                165                 :                : /*
                                166                 :                :  * Append a binary integer to a StringInfo buffer
                                167                 :                :  *
                                168                 :                :  * This function is deprecated; prefer use of the functions above.
                                169                 :                :  */
                                170                 :                : static inline void
 2730                           171                 :         115165 : pq_sendint(StringInfo buf, uint32 i, int b)
                                172                 :                : {
 2988                           173   [ -  -  +  - ]:         115165 :     switch (b)
                                174                 :                :     {
 2988 andres@anarazel.de        175                 :UBC           0 :         case 1:
 2730                           176                 :              0 :             pq_sendint8(buf, (uint8) i);
 2988                           177                 :              0 :             break;
                                178                 :              0 :         case 2:
 2730                           179                 :              0 :             pq_sendint16(buf, (uint16) i);
 2988                           180                 :              0 :             break;
 2988 andres@anarazel.de        181                 :CBC      115165 :         case 4:
 2730                           182                 :         115165 :             pq_sendint32(buf, (uint32) i);
 2988                           183                 :         115165 :             break;
 2988 andres@anarazel.de        184                 :UBC           0 :         default:
                                185         [ #  # ]:              0 :             elog(ERROR, "unsupported integer size %d", b);
                                186                 :                :             break;
                                187                 :                :     }
 2988 andres@anarazel.de        188                 :CBC      115165 : }
                                189                 :                : 
                                190                 :                : 
                                191                 :                : extern void pq_begintypsend(StringInfo buf);
                                192                 :                : extern bytea *pq_endtypsend(StringInfo buf);
                                193                 :                : 
                                194                 :                : extern void pq_puttextmessage(char msgtype, const char *str);
                                195                 :                : extern void pq_putemptymessage(char msgtype);
                                196                 :                : 
                                197                 :                : extern int  pq_getmsgbyte(StringInfo msg);
                                198                 :                : extern unsigned int pq_getmsgint(StringInfo msg, int b);
                                199                 :                : extern int64 pq_getmsgint64(StringInfo msg);
                                200                 :                : extern float4 pq_getmsgfloat4(StringInfo msg);
                                201                 :                : extern float8 pq_getmsgfloat8(StringInfo msg);
                                202                 :                : extern const char *pq_getmsgbytes(StringInfo msg, int datalen);
                                203                 :                : extern void pq_copymsgbytes(StringInfo msg, void *buf, int datalen);
                                204                 :                : extern char *pq_getmsgtext(StringInfo msg, int rawbytes, int *nbytes);
                                205                 :                : extern const char *pq_getmsgstring(StringInfo msg);
                                206                 :                : extern const char *pq_getmsgrawstring(StringInfo msg);
                                207                 :                : extern void pq_getmsgend(StringInfo msg);
                                208                 :                : 
                                209                 :                : #endif                          /* PQFORMAT_H */
        

Generated by: LCOV version 2.4-beta