github.com/tumi8/quic-go@v0.37.4-tum/noninternal/wire/stream_data_blocked_frame.go (about)

     1  package wire
     2  
     3  import (
     4  	"bytes"
     5  
     6  	"github.com/tumi8/quic-go/noninternal/protocol"
     7  	"github.com/tumi8/quic-go/quicvarint"
     8  )
     9  
    10  // A StreamDataBlockedFrame is a STREAM_DATA_BLOCKED frame
    11  type StreamDataBlockedFrame struct {
    12  	StreamID          protocol.StreamID
    13  	MaximumStreamData protocol.ByteCount
    14  }
    15  
    16  func parseStreamDataBlockedFrame(r *bytes.Reader, _ protocol.VersionNumber) (*StreamDataBlockedFrame, error) {
    17  	sid, err := quicvarint.Read(r)
    18  	if err != nil {
    19  		return nil, err
    20  	}
    21  	offset, err := quicvarint.Read(r)
    22  	if err != nil {
    23  		return nil, err
    24  	}
    25  
    26  	return &StreamDataBlockedFrame{
    27  		StreamID:          protocol.StreamID(sid),
    28  		MaximumStreamData: protocol.ByteCount(offset),
    29  	}, nil
    30  }
    31  
    32  func (f *StreamDataBlockedFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
    33  	b = append(b, 0x15)
    34  	b = quicvarint.Append(b, uint64(f.StreamID))
    35  	b = quicvarint.Append(b, uint64(f.MaximumStreamData))
    36  	return b, nil
    37  }
    38  
    39  // Length of a written frame
    40  func (f *StreamDataBlockedFrame) Length(version protocol.VersionNumber) protocol.ByteCount {
    41  	return 1 + quicvarint.Len(uint64(f.StreamID)) + quicvarint.Len(uint64(f.MaximumStreamData))
    42  }