github.com/quic-go/quic-go@v0.44.0/internal/wire/max_data_frame.go (about) 1 package wire 2 3 import ( 4 "github.com/quic-go/quic-go/internal/protocol" 5 "github.com/quic-go/quic-go/quicvarint" 6 ) 7 8 // A MaxDataFrame carries flow control information for the connection 9 type MaxDataFrame struct { 10 MaximumData protocol.ByteCount 11 } 12 13 // parseMaxDataFrame parses a MAX_DATA frame 14 func parseMaxDataFrame(b []byte, _ protocol.Version) (*MaxDataFrame, int, error) { 15 frame := &MaxDataFrame{} 16 byteOffset, l, err := quicvarint.Parse(b) 17 if err != nil { 18 return nil, 0, replaceUnexpectedEOF(err) 19 } 20 frame.MaximumData = protocol.ByteCount(byteOffset) 21 return frame, l, nil 22 } 23 24 func (f *MaxDataFrame) Append(b []byte, _ protocol.Version) ([]byte, error) { 25 b = append(b, maxDataFrameType) 26 b = quicvarint.Append(b, uint64(f.MaximumData)) 27 return b, nil 28 } 29 30 // Length of a written frame 31 func (f *MaxDataFrame) Length(_ protocol.Version) protocol.ByteCount { 32 return 1 + protocol.ByteCount(quicvarint.Len(uint64(f.MaximumData))) 33 }