Skip to content

Commit

Permalink
[PH2][Refactor][Minor] Remove magic number for clarity (grpc#38166)
Browse files Browse the repository at this point in the history
[PH2][Refactor][Minor] Remove magic number for clarity.
Using GRPC_HEADER_SIZE_IN_BYTES to make clear that we are parsing the gRPC header.

Closes grpc#38166

COPYBARA_INTEGRATE_REVIEW=grpc#38166 from tanvi-jagtap:remove_magic_number f35baa3
PiperOrigin-RevId: 700536771
  • Loading branch information
tanvi-jagtap authored and copybara-github committed Nov 27, 2024
1 parent 18feac3 commit 9d9a89a
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/core/ext/transport/chttp2/transport/frame_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,16 @@ grpc_core::Poll<grpc_error_handle> grpc_deframe_unprocessed_incoming_frames(
grpc_slice_buffer* slices = &s->frame_storage;
grpc_error_handle error;

if (slices->length < 5) {
if (min_progress_size != nullptr) *min_progress_size = 5 - slices->length;
if (slices->length < GRPC_HEADER_SIZE_IN_BYTES) {
if (min_progress_size != nullptr) {
*min_progress_size = GRPC_HEADER_SIZE_IN_BYTES - slices->length;
}
return grpc_core::Pending{};
}

uint8_t header[5];
grpc_slice_buffer_copy_first_into_buffer(slices, 5, header);
uint8_t header[GRPC_HEADER_SIZE_IN_BYTES];
grpc_slice_buffer_copy_first_into_buffer(slices, GRPC_HEADER_SIZE_IN_BYTES,
header);

switch (header[0]) {
case 0:
Expand All @@ -114,18 +117,20 @@ grpc_core::Poll<grpc_error_handle> grpc_deframe_unprocessed_incoming_frames(
(static_cast<uint32_t>(header[3]) << 8) |
static_cast<uint32_t>(header[4]);

if (slices->length < length + 5) {
if (slices->length < length + GRPC_HEADER_SIZE_IN_BYTES) {
if (min_progress_size != nullptr) {
*min_progress_size = length + 5 - slices->length;
*min_progress_size = length + GRPC_HEADER_SIZE_IN_BYTES - slices->length;
}
return grpc_core::Pending{};
}

if (min_progress_size != nullptr) *min_progress_size = 0;

if (stream_out != nullptr) {
s->call_tracer_wrapper.RecordIncomingBytes({5, length, 0});
grpc_slice_buffer_move_first_into_buffer(slices, 5, header);
s->call_tracer_wrapper.RecordIncomingBytes(
{GRPC_HEADER_SIZE_IN_BYTES, length, 0});
grpc_slice_buffer_move_first_into_buffer(slices, GRPC_HEADER_SIZE_IN_BYTES,
header);
grpc_slice_buffer_move_first(slices, length, stream_out->c_slice_buffer());
}

Expand Down

0 comments on commit 9d9a89a

Please sign in to comment.