code/quic-toy-server/net/quic/core/quic_framer.cc
// Add a new ietf-format stream frame.
// Bits controlling whether there is a frame-length and frame-offset
// are in the QuicStreamFrame.
Add a new ietf-format stream frame.
Bits controlling whether there is a frame-length and frame-offset
are in the QuicStreamFrame.
Add a new ietf - format stream frame . Bits controlling whether there is a frame - length and frame - offset are in the QuicStreamFrame .
bool QuicFramer::AppendIetfStreamFrame(const QuicStreamFrame& frame,
                                       bool last_frame_in_packet,
                                       QuicDataWriter* writer) {
  uint8_t frame_type = static_cast<uint8_t>(IETF_STREAM);
  if (frame.fin) {
    frame_type |= IETF_STREAM_FRAME_FIN_BIT;
  }
  if (frame.offset != 0) {
    frame_type |= IETF_STREAM_FRAME_OFF_BIT;
  }
  if (!last_frame_in_packet) {
    frame_type |= IETF_STREAM_FRAME_LEN_BIT;
  }
  if (writer->WriteUInt8(frame_type) == false) {
    set_detailed_error("Unable to write frame-type.");
    return false;
  }
  if (writer->WriteVarInt62(static_cast<uint64_t>(frame.stream_id)) == false) {
    set_detailed_error("Writing stream id failed.");
    return false;
  }
  if (frame_type & IETF_STREAM_FRAME_OFF_BIT) {
    if (writer->WriteVarInt62(static_cast<uint64_t>(frame.offset)) == false) {
      set_detailed_error("Writing data offset failed.");
      return false;
    }
  }
  if (frame_type & IETF_STREAM_FRAME_LEN_BIT) {
    if (writer->WriteVarInt62(frame.data_length) == false) {
      set_detailed_error("Writing data length failed.");
      return false;
    }
  }
  if (data_producer_ == nullptr) {
    if (!writer->WriteBytes(frame.data_buffer, frame.data_length)) {
      set_detailed_error("Writing frame data failed.");
      return false;
    }
  } else {
    DCHECK_EQ(nullptr, frame.data_buffer);
    if (!data_producer_->WriteStreamData(frame.stream_id, frame.offset,
                                         frame.data_length, writer)) {
      set_detailed_error("Writing frame data failed.");
      return false;
    }
  }
  return true;
}
bool QuicFramer :: AppendIetfStreamFrame ( const QuicStreamFrame & frame , bool last_frame_in_packet , QuicDataWriter * writer ) { uint8_t frame_type = static_cast < uint8_t > ( IETF_STREAM ) ; if ( frame . fin ) { frame_type |= IETF_STREAM_FRAME_FIN_BIT ; } if ( frame . offset != 0 ) { frame_type |= IETF_STREAM_FRAME_OFF_BIT ; } if ( ! last_frame_in_packet ) { frame_type |= IETF_STREAM_FRAME_LEN_BIT ; } if ( writer -> WriteUInt8 ( frame_type ) == false ) { set_detailed_error ( " " ) ; return false ; } if ( writer -> WriteVarInt62 ( static_cast < uint64_t > ( frame . stream_id ) ) == false ) { set_detailed_error ( " " ) ; return false ; } if ( frame_type & IETF_STREAM_FRAME_OFF_BIT ) { if ( writer -> WriteVarInt62 ( static_cast < uint64_t > ( frame . offset ) ) == false ) { set_detailed_error ( " " ) ; return false ; } } if ( frame_type & IETF_STREAM_FRAME_LEN_BIT ) { if ( writer -> WriteVarInt62 ( frame . data_length ) == false ) { set_detailed_error ( " " ) ; return false ; } } if ( data_producer_ == nullptr ) { if ( ! writer -> WriteBytes ( frame . data_buffer , frame . data_length ) ) { set_detailed_error ( " " ) ; return false ; } } else { DCHECK_EQ ( nullptr , frame . data_buffer ) ; if ( ! data_producer_ -> WriteStreamData ( frame . stream_id , frame . offset , frame . data_length , writer ) ) { set_detailed_error ( " " ) ; return false ; } } return true ; }
Add a new ietf-format stream frame.
Add a new ietf - format stream frame .
// figure out whether we will have FIN, LEN, and/or OFFSET fields // in the packet and create a type-byte with the proper flag settings. // Calculate how long the header and type byte will be. This // is done so that we can determine how much data can be placed in // the packet _after_ doing the header. Start the length with the // encoded size of the streamid and type byte. // We will include the frame offset if it is not 0 // If not the last frame in the packet, include the length field. // Put the type-byte in the header. // Stream ID always goes in the header... // Offset may go in the header... // Frame data length... // now move the data in // data comes from the frame's buffer -- append the necessary // number of bytes to the frame.