1 /* 2 * 3 * Copyright 2015 gRPC authors. 4 * 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 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 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. 16 * 17 */ 18 19 #ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_FRAME_DATA_H 20 #define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_FRAME_DATA_H 21 22 /* Parser for GRPC streams embedded in DATA frames */ 23 24 #include <grpc/support/port_platform.h> 25 26 #include <grpc/slice.h> 27 #include <grpc/slice_buffer.h> 28 29 #include "src/core/ext/transport/chttp2/transport/frame.h" 30 #include "src/core/lib/transport/byte_stream.h" 31 #include "src/core/lib/transport/transport.h" 32 33 typedef enum { 34 GRPC_CHTTP2_DATA_FH_0, 35 GRPC_CHTTP2_DATA_FH_1, 36 GRPC_CHTTP2_DATA_FH_2, 37 GRPC_CHTTP2_DATA_FH_3, 38 GRPC_CHTTP2_DATA_FH_4, 39 GRPC_CHTTP2_DATA_FRAME, 40 GRPC_CHTTP2_DATA_ERROR 41 } grpc_chttp2_stream_state; 42 43 namespace grpc_core { 44 class Chttp2IncomingByteStream; 45 } // namespace grpc_core 46 47 struct grpc_chttp2_data_parser { 48 grpc_chttp2_data_parser() = default; 49 ~grpc_chttp2_data_parser(); 50 51 grpc_chttp2_stream_state state = GRPC_CHTTP2_DATA_FH_0; 52 uint8_t frame_type = 0; 53 uint32_t frame_size = 0; 54 grpc_error_handle error = GRPC_ERROR_NONE; 55 56 bool is_frame_compressed = false; 57 grpc_core::Chttp2IncomingByteStream* parsing_frame = nullptr; 58 }; 59 60 /* start processing a new data frame */ 61 grpc_error_handle grpc_chttp2_data_parser_begin_frame( 62 grpc_chttp2_data_parser* parser, uint8_t flags, uint32_t stream_id, 63 grpc_chttp2_stream* s); 64 65 /* handle a slice of a data frame - is_last indicates the last slice of a 66 frame */ 67 grpc_error_handle grpc_chttp2_data_parser_parse(void* parser, 68 grpc_chttp2_transport* t, 69 grpc_chttp2_stream* s, 70 const grpc_slice& slice, 71 int is_last); 72 73 void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer* inbuf, 74 uint32_t write_bytes, int is_eof, 75 grpc_transport_one_way_stats* stats, 76 grpc_slice_buffer* outbuf); 77 78 grpc_error_handle grpc_deframe_unprocessed_incoming_frames( 79 grpc_chttp2_data_parser* p, grpc_chttp2_stream* s, 80 grpc_slice_buffer* slices, grpc_slice* slice_out, 81 grpc_core::OrphanablePtr<grpc_core::ByteStream>* stream_out); 82 83 #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_FRAME_DATA_H */ 84