github.com/metacubex/quic-go@v0.44.1-0.20240520163451-20b689a59136/internal/wire/stop_sending_frame.go (about) 1 package wire 2 3 import ( 4 "github.com/metacubex/quic-go/internal/protocol" 5 "github.com/metacubex/quic-go/internal/qerr" 6 "github.com/metacubex/quic-go/quicvarint" 7 ) 8 9 // A StopSendingFrame is a STOP_SENDING frame 10 type StopSendingFrame struct { 11 StreamID protocol.StreamID 12 ErrorCode qerr.StreamErrorCode 13 } 14 15 // parseStopSendingFrame parses a STOP_SENDING frame 16 func parseStopSendingFrame(b []byte, _ protocol.Version) (*StopSendingFrame, int, error) { 17 startLen := len(b) 18 streamID, l, err := quicvarint.Parse(b) 19 if err != nil { 20 return nil, 0, replaceUnexpectedEOF(err) 21 } 22 b = b[l:] 23 errorCode, l, err := quicvarint.Parse(b) 24 if err != nil { 25 return nil, 0, replaceUnexpectedEOF(err) 26 } 27 b = b[l:] 28 29 return &StopSendingFrame{ 30 StreamID: protocol.StreamID(streamID), 31 ErrorCode: qerr.StreamErrorCode(errorCode), 32 }, startLen - len(b), nil 33 } 34 35 // Length of a written frame 36 func (f *StopSendingFrame) Length(_ protocol.Version) protocol.ByteCount { 37 return 1 + protocol.ByteCount(quicvarint.Len(uint64(f.StreamID))+quicvarint.Len(uint64(f.ErrorCode))) 38 } 39 40 func (f *StopSendingFrame) Append(b []byte, _ protocol.Version) ([]byte, error) { 41 b = append(b, stopSendingFrameType) 42 b = quicvarint.Append(b, uint64(f.StreamID)) 43 b = quicvarint.Append(b, uint64(f.ErrorCode)) 44 return b, nil 45 }