route/vendor/github.com/lucas-clemente/quic-go/internal/wire/blocked_frame.go

46 lines
1.1 KiB
Go
Raw Normal View History

2018-01-03 19:19:49 +00:00
package wire
import (
"bytes"
"github.com/lucas-clemente/quic-go/internal/protocol"
2018-01-20 18:07:01 +00:00
"github.com/lucas-clemente/quic-go/internal/utils"
2018-01-03 19:19:49 +00:00
)
// A BlockedFrame is a BLOCKED frame
2018-01-20 18:07:01 +00:00
type BlockedFrame struct {
Offset protocol.ByteCount
}
2018-01-03 19:19:49 +00:00
// ParseBlockedFrame parses a BLOCKED frame
2018-01-20 18:07:01 +00:00
func ParseBlockedFrame(r *bytes.Reader, _ protocol.VersionNumber) (*BlockedFrame, error) {
2018-01-03 19:19:49 +00:00
if _, err := r.ReadByte(); err != nil {
return nil, err
}
2018-01-20 18:07:01 +00:00
offset, err := utils.ReadVarInt(r)
if err != nil {
return nil, err
}
return &BlockedFrame{
Offset: protocol.ByteCount(offset),
}, nil
2018-01-03 19:19:49 +00:00
}
func (f *BlockedFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error {
if !version.UsesIETFFrameFormat() {
return (&blockedFrameLegacy{}).Write(b, version)
}
typeByte := uint8(0x08)
b.WriteByte(typeByte)
2018-01-20 18:07:01 +00:00
utils.WriteVarInt(b, uint64(f.Offset))
2018-01-03 19:19:49 +00:00
return nil
}
// MinLength of a written frame
2018-01-20 18:07:01 +00:00
func (f *BlockedFrame) MinLength(version protocol.VersionNumber) protocol.ByteCount {
if !version.UsesIETFFrameFormat() {
return 1 + 4
2018-01-03 19:19:49 +00:00
}
2018-01-20 18:07:01 +00:00
return 1 + utils.VarIntLen(uint64(f.Offset))
2018-01-03 19:19:49 +00:00
}