1 // Copyright 2024 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 #pragma once 16 17 #include <cstdint> 18 19 #include "pw_bytes/span.h" 20 #include "pw_result/result.h" 21 #include "pw_string/string.h" 22 23 namespace pw::grpc { 24 25 // We disable the HPACK dynamic header table. 26 inline constexpr uint32_t kHpackDynamicHeaderTableSize = 0; 27 28 // Maximum size of a string that can be returned by this API. 29 inline constexpr uint32_t kHpackMaxStringSize = 127; 30 31 // Parses a request header field block, returning the grpc method name. 32 Result<InlineString<kHpackMaxStringSize>> HpackParseRequestHeaders( 33 ConstByteSpan payload); 34 35 // Decodes an HPACK integer. 36 // Consumed bytes are removed from the `input` span. 37 Result<int> HpackIntegerDecode(ConstByteSpan& input, int bits_in_first_byte); 38 39 // Decodes an HPACK string. 40 // Consumed bytes are removed from the `input` span. 41 Result<InlineString<kHpackMaxStringSize>> HpackStringDecode( 42 ConstByteSpan& input); 43 44 // Decodes a Huffman-encoded string. 45 Result<InlineString<kHpackMaxStringSize>> HpackHuffmanDecode( 46 ConstByteSpan input); 47 48 // Returns a HEADERS payload to use for grpc Response-Headers. 49 ConstByteSpan ResponseHeadersPayload(); 50 51 // Returns a HEADERS payload to use for grpc Trailers. 52 ConstByteSpan ResponseTrailersPayload(Status response_code); 53 54 } // namespace pw::grpc 55