3 * Copyright 2015 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include <grpc/support/port_platform.h>
21 #include "src/core/ext/transport/chttp2/transport/varint.h"
23 uint32_t grpc_chttp2_hpack_varint_length(uint32_t tail_value) {
24 if (tail_value < (1 << 7)) {
26 } else if (tail_value < (1 << 14)) {
28 } else if (tail_value < (1 << 21)) {
30 } else if (tail_value < (1 << 28)) {
37 void grpc_chttp2_hpack_write_varint_tail(uint32_t tail_value, uint8_t* target,
38 uint32_t tail_length) {
39 switch (tail_length) {
41 target[4] = static_cast<uint8_t>((tail_value >> 28) | 0x80);
44 target[3] = static_cast<uint8_t>((tail_value >> 21) | 0x80);
47 target[2] = static_cast<uint8_t>((tail_value >> 14) | 0x80);
50 target[1] = static_cast<uint8_t>((tail_value >> 7) | 0x80);
53 target[0] = static_cast<uint8_t>((tail_value) | 0x80);
55 target[tail_length - 1] &= 0x7f;