Skip to content

Commit a55443d

Browse files
authored
Replaced sizeof(frame_header_type) with SIZE_OF_FRAME_LENGTH_AND_FLAGS [HZ-5297] (hazelcast#1386)
Replaced `sizeof(frame_header_type)` with `SIZE_OF_FRAME_LENGTH_AND_FLAGS`. fixes hazelcast#1385 (comment)
1 parent 36fba37 commit a55443d

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

hazelcast/include/hazelcast/client/protocol/ClientMessage.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ class HAZELCAST_API ClientMessage
11791179
bool isNull = (nullptr == value);
11801180
if (isNull) {
11811181
auto* h = reinterpret_cast<frame_header_type*>(
1182-
wr_ptr(sizeof(frame_header_type)));
1182+
wr_ptr(SIZE_OF_FRAME_LENGTH_AND_FLAGS));
11831183
*h = null_frame();
11841184
if (is_final) {
11851185
h->flags |= IS_FINAL_FLAG;
@@ -1196,9 +1196,9 @@ class HAZELCAST_API ClientMessage
11961196
inline void set(const std::string& value, bool is_final = false)
11971197
{
11981198
auto h = reinterpret_cast<frame_header_type*>(
1199-
wr_ptr(sizeof(frame_header_type)));
1199+
wr_ptr(SIZE_OF_FRAME_LENGTH_AND_FLAGS));
12001200
auto len = value.length();
1201-
h->frame_len = sizeof(frame_header_type) + len;
1201+
h->frame_len = SIZE_OF_FRAME_LENGTH_AND_FLAGS + len;
12021202
if (is_final) {
12031203
h->flags |= IS_FINAL_FLAG;
12041204
}
@@ -1286,15 +1286,15 @@ class HAZELCAST_API ClientMessage
12861286
{
12871287
if (value.data_size() == 0) {
12881288
auto* h = reinterpret_cast<frame_header_type*>(
1289-
wr_ptr(sizeof(frame_header_type)));
1289+
wr_ptr(SIZE_OF_FRAME_LENGTH_AND_FLAGS));
12901290
*h = null_frame();
12911291
if (is_final) {
12921292
h->flags |= IS_FINAL_FLAG;
12931293
}
12941294
return;
12951295
}
12961296
auto& bytes = value.to_byte_array();
1297-
auto frame_length = sizeof(frame_header_type) + bytes.size();
1297+
auto frame_length = SIZE_OF_FRAME_LENGTH_AND_FLAGS + bytes.size();
12981298
auto fp = wr_ptr(frame_length);
12991299
auto* header = reinterpret_cast<frame_header_type*>(fp);
13001300
header->frame_len = frame_length;
@@ -1345,15 +1345,15 @@ class HAZELCAST_API ClientMessage
13451345
void set(const std::vector<T>& values, bool is_final = false)
13461346
{
13471347
auto* h = reinterpret_cast<frame_header_type*>(
1348-
wr_ptr(sizeof(frame_header_type)));
1348+
wr_ptr(SIZE_OF_FRAME_LENGTH_AND_FLAGS));
13491349
*h = begin_frame();
13501350

13511351
for (auto& item : values) {
13521352
set(item);
13531353
}
13541354

13551355
h = reinterpret_cast<frame_header_type*>(
1356-
wr_ptr(sizeof(frame_header_type)));
1356+
wr_ptr(SIZE_OF_FRAME_LENGTH_AND_FLAGS));
13571357
*h = end_frame();
13581358
if (is_final) {
13591359
h->flags |= IS_FINAL_FLAG;
@@ -1569,14 +1569,14 @@ class HAZELCAST_API ClientMessage
15691569
void add_begin_frame()
15701570
{
15711571
auto* f = reinterpret_cast<frame_header_type*>(
1572-
wr_ptr(sizeof(frame_header_type)));
1572+
wr_ptr(SIZE_OF_FRAME_LENGTH_AND_FLAGS));
15731573
*f = begin_frame();
15741574
}
15751575

15761576
void add_end_frame(bool is_final)
15771577
{
15781578
auto ef = reinterpret_cast<frame_header_type*>(
1579-
wr_ptr(sizeof(frame_header_type)));
1579+
wr_ptr(SIZE_OF_FRAME_LENGTH_AND_FLAGS));
15801580
*ef = end_frame();
15811581
if (is_final) {
15821582
ef->flags |= IS_FINAL_FLAG;

hazelcast/src/hazelcast/client/protocol.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ ClientMessage::fast_forward_to_end_frame()
390390
int number_expected_frames = 1;
391391
while (number_expected_frames) {
392392
auto* f = reinterpret_cast<frame_header_type*>(
393-
rd_ptr(sizeof(frame_header_type)));
393+
rd_ptr(SIZE_OF_FRAME_LENGTH_AND_FLAGS));
394394

395395
int16_t flags = f->flags;
396396
if (is_flag_set(flags, END_DATA_STRUCTURE_FLAG)) {
@@ -400,7 +400,8 @@ ClientMessage::fast_forward_to_end_frame()
400400
}
401401

402402
// skip current frame
403-
rd_ptr(static_cast<int32_t>(f->frame_len) - sizeof(frame_header_type));
403+
rd_ptr(static_cast<int32_t>(f->frame_len) -
404+
SIZE_OF_FRAME_LENGTH_AND_FLAGS);
404405
}
405406
}
406407

0 commit comments

Comments
 (0)