github.com/sagernet/quic-go@v0.43.1-beta.1/internal/wire/data_blocked_frame.go (about)

     1  package wire
     2  
     3  import (
     4  	"bytes"
     5  
     6  	"github.com/sagernet/quic-go/internal/protocol"
     7  	"github.com/sagernet/quic-go/quicvarint"
     8  )
     9  
    10  // A DataBlockedFrame is a DATA_BLOCKED frame
    11  type DataBlockedFrame struct {
    12  	MaximumData protocol.ByteCount
    13  }
    14  
    15  func parseDataBlockedFrame(r *bytes.Reader, _ protocol.Version) (*DataBlockedFrame, error) {
    16  	offset, err := quicvarint.Read(r)
    17  	if err != nil {
    18  		return nil, err
    19  	}
    20  	return &DataBlockedFrame{MaximumData: protocol.ByteCount(offset)}, nil
    21  }
    22  
    23  func (f *DataBlockedFrame) Append(b []byte, version protocol.Version) ([]byte, error) {
    24  	b = append(b, dataBlockedFrameType)
    25  	return quicvarint.Append(b, uint64(f.MaximumData)), nil
    26  }
    27  
    28  // Length of a written frame
    29  func (f *DataBlockedFrame) Length(version protocol.Version) protocol.ByteCount {
    30  	return 1 + protocol.ByteCount(quicvarint.Len(uint64(f.MaximumData)))
    31  }