Skip to content

Commit bcfcd0b

Browse files
committed
Merge conformance-tests into main for v0.5.0 release
2 parents 01e517a + cdf303f commit bcfcd0b

5 files changed

Lines changed: 20 additions & 12 deletions

File tree

META.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "pgproto",
33
"abstract": "Native Protobuf support for PostgreSQL",
4-
"version": "0.4.0",
4+
"version": "0.5.0",
55

66

77
"maintainer": "paezmartinez <paezmartinez@google.com>",
@@ -10,7 +10,7 @@
1010
"pgproto": {
1111
"abstract": "Native Protobuf support for PostgreSQL",
1212
"file": "sql/pgproto--1.0.sql",
13-
"version": "0.4.0"
13+
"version": "0.5.0"
1414

1515

1616
}

src/gin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extract_single_key(const char **ptr, const char *end, char *key_str)
2727
sprintf(key_str, "%d=%lu", field_num, (long)val);
2828
break;
2929
case PB_WIRE_FIXED64:
30-
*ptr += 8;
30+
*ptr += PB_WIRE_FIXED64_SIZE;
3131
sprintf(key_str, "%d=64bit", field_num);
3232
break;
3333
case PB_WIRE_LENGTH_DELIMITED:
@@ -38,7 +38,7 @@ extract_single_key(const char **ptr, const char *end, char *key_str)
3838
}
3939
break;
4040
case PB_WIRE_FIXED32:
41-
*ptr += 4;
41+
*ptr += PB_WIRE_FIXED32_SIZE;
4242
sprintf(key_str, "%d=32bit", field_num);
4343
break;
4444
default:

src/io.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ protobuf_in(PG_FUNCTION_ARGS)
2525
ProtobufData *result;
2626
size_t data_len;
2727

28-
if (len >= 2 && str[0] == '\\' && str[1] == 'x') {
29-
str += 2;
30-
len -= 2;
28+
if (len >= HEX_PREFIX_LEN && str[0] == '\\' && str[1] == 'x') {
29+
str += HEX_PREFIX_LEN;
30+
len -= HEX_PREFIX_LEN;
3131
}
3232

3333
if (len % 2 != 0) {
@@ -44,7 +44,7 @@ protobuf_in(PG_FUNCTION_ARGS)
4444
if (hi < 0 || lo < 0) {
4545
elog(ERROR, "Invalid character in hex string");
4646
}
47-
result->data[i] = (hi << 4) | lo;
47+
result->data[i] = (hi << HEX_CHAR_BITS) | lo;
4848
}
4949

5050
PG_RETURN_POINTER(result);
@@ -75,9 +75,9 @@ protobuf_out(PG_FUNCTION_ARGS)
7575
result_str[1] = 'x';
7676

7777
for (i = 0; i < len; i++) {
78-
sprintf(result_str + 2 + i * 2, "%02x", (unsigned char) data->data[i]);
78+
sprintf(result_str + HEX_PREFIX_LEN + i * 2, "%02x", (unsigned char) data->data[i]);
7979
}
80-
result_str[len * 2 + 2] = '\0';
80+
result_str[len * 2 + HEX_PREFIX_LEN] = '\0';
8181

8282
PG_RETURN_CSTRING(result_str);
8383
}

src/json.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ pb_to_json_inner(const char *ptr, const char *end, const char *msg_name, StringI
1515

1616
while (ptr < end) {
1717
uint64 key = decode_varint(&ptr, end);
18-
int field_num = (int)(key >> 3);
19-
int wire_type = (int)(key & 0x07);
18+
int field_num = (int)(key >> PB_FIELD_NUM_SHIFT);
19+
int wire_type = (int)(key & PB_WIRE_TYPE_MASK);
2020

2121
PbFieldLookup lookup;
2222
if (pgproto_lookup_field_by_number(msg_name, (uint32_t)field_num, &lookup) == PB_LOOKUP_OK) {

src/pgproto.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ typedef enum {
6565
#define PB_MAP_ENTRY_KEY 1
6666
#define PB_MAP_ENTRY_VALUE 2
6767

68+
/* Fixed-size wire types sizes */
69+
#define PB_WIRE_FIXED64_SIZE 8
70+
#define PB_WIRE_FIXED32_SIZE 4
71+
72+
/* Hexadecimal conversion constants */
73+
#define HEX_CHAR_BITS 4
74+
#define HEX_PREFIX_LEN 2
75+
6876
/*
6977
* PbType: Protobuf field types as defined in descriptor.proto.
7078
*/

0 commit comments

Comments
 (0)