Home | History | Annotate | Download | only in transport
      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 #include "src/core/ext/transport/chttp2/transport/frame.h"
     29 #include "src/core/lib/transport/byte_stream.h"
     30 #include "src/core/lib/transport/transport.h"
     31 
     32 typedef enum {
     33   GRPC_CHTTP2_DATA_FH_0,
     34   GRPC_CHTTP2_DATA_FH_1,
     35   GRPC_CHTTP2_DATA_FH_2,
     36   GRPC_CHTTP2_DATA_FH_3,
     37   GRPC_CHTTP2_DATA_FH_4,
     38   GRPC_CHTTP2_DATA_FRAME,
     39   GRPC_CHTTP2_DATA_ERROR
     40 } grpc_chttp2_stream_state;
     41 
     42 namespace grpc_core {
     43 class Chttp2IncomingByteStream;
     44 }  // namespace grpc_core
     45 
     46 typedef struct {
     47   grpc_chttp2_stream_state state;
     48   uint8_t frame_type;
     49   uint32_t frame_size;
     50   grpc_error* error;
     51 
     52   bool is_frame_compressed;
     53   grpc_core::Chttp2IncomingByteStream* parsing_frame;
     54 } grpc_chttp2_data_parser;
     55 
     56 /* initialize per-stream state for data frame parsing */
     57 grpc_error* grpc_chttp2_data_parser_init(grpc_chttp2_data_parser* parser);
     58 
     59 void grpc_chttp2_data_parser_destroy(grpc_chttp2_data_parser* parser);
     60 
     61 /* start processing a new data frame */
     62 grpc_error* grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser* parser,
     63                                                 uint8_t flags,
     64                                                 uint32_t stream_id,
     65                                                 grpc_chttp2_stream* s);
     66 
     67 /* handle a slice of a data frame - is_last indicates the last slice of a
     68    frame */
     69 grpc_error* grpc_chttp2_data_parser_parse(void* parser,
     70                                           grpc_chttp2_transport* t,
     71                                           grpc_chttp2_stream* s,
     72                                           grpc_slice slice, int is_last);
     73 
     74 void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer* inbuf,
     75                              uint32_t write_bytes, int is_eof,
     76                              grpc_transport_one_way_stats* stats,
     77                              grpc_slice_buffer* outbuf);
     78 
     79 grpc_error* grpc_deframe_unprocessed_incoming_frames(
     80     grpc_chttp2_data_parser* p, grpc_chttp2_stream* s,
     81     grpc_slice_buffer* slices, grpc_slice* slice_out,
     82     grpc_core::OrphanablePtr<grpc_core::ByteStream>* stream_out);
     83 
     84 #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_FRAME_DATA_H */
     85