github.com/metacubex/quic-go@v0.44.1-0.20240520163451-20b689a59136/internal/wire/data_blocked_frame.go (about)

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