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