mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package wire
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/refraction-networking/uquic/internal/protocol"
|
|
"github.com/refraction-networking/uquic/internal/qerr"
|
|
"github.com/refraction-networking/uquic/quicvarint"
|
|
)
|
|
|
|
// A ResetStreamFrame is a RESET_STREAM frame in QUIC
|
|
type ResetStreamFrame struct {
|
|
StreamID protocol.StreamID
|
|
ErrorCode qerr.StreamErrorCode
|
|
FinalSize protocol.ByteCount
|
|
}
|
|
|
|
func parseResetStreamFrame(r *bytes.Reader, _ protocol.Version) (*ResetStreamFrame, error) {
|
|
var streamID protocol.StreamID
|
|
var byteOffset protocol.ByteCount
|
|
sid, err := quicvarint.Read(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
streamID = protocol.StreamID(sid)
|
|
errorCode, err := quicvarint.Read(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
bo, err := quicvarint.Read(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
byteOffset = protocol.ByteCount(bo)
|
|
|
|
return &ResetStreamFrame{
|
|
StreamID: streamID,
|
|
ErrorCode: qerr.StreamErrorCode(errorCode),
|
|
FinalSize: byteOffset,
|
|
}, nil
|
|
}
|
|
|
|
func (f *ResetStreamFrame) Append(b []byte, _ protocol.Version) ([]byte, error) {
|
|
b = append(b, resetStreamFrameType)
|
|
b = quicvarint.Append(b, uint64(f.StreamID))
|
|
b = quicvarint.Append(b, uint64(f.ErrorCode))
|
|
b = quicvarint.Append(b, uint64(f.FinalSize))
|
|
return b, nil
|
|
}
|
|
|
|
// Length of a written frame
|
|
func (f *ResetStreamFrame) Length(version protocol.Version) protocol.ByteCount {
|
|
return 1 + quicvarint.Len(uint64(f.StreamID)) + quicvarint.Len(uint64(f.ErrorCode)) + quicvarint.Len(uint64(f.FinalSize))
|
|
}
|