uquic/internal/wire/max_stream_data_frame.go
Marten Seemann 11c5045065 move varint encoding / decoding to a separate package
... which is not internal.
2021-01-01 11:46:45 +08:00

46 lines
1.2 KiB
Go

package wire
import (
"bytes"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/quicvarint"
)
// A MaxStreamDataFrame is a MAX_STREAM_DATA frame
type MaxStreamDataFrame struct {
StreamID protocol.StreamID
MaximumStreamData protocol.ByteCount
}
func parseMaxStreamDataFrame(r *bytes.Reader, _ protocol.VersionNumber) (*MaxStreamDataFrame, error) {
if _, err := r.ReadByte(); err != nil {
return nil, err
}
sid, err := quicvarint.ReadVarInt(r)
if err != nil {
return nil, err
}
offset, err := quicvarint.ReadVarInt(r)
if err != nil {
return nil, err
}
return &MaxStreamDataFrame{
StreamID: protocol.StreamID(sid),
MaximumStreamData: protocol.ByteCount(offset),
}, nil
}
func (f *MaxStreamDataFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error {
b.WriteByte(0x11)
quicvarint.WriteVarInt(b, uint64(f.StreamID))
quicvarint.WriteVarInt(b, uint64(f.MaximumStreamData))
return nil
}
// Length of a written frame
func (f *MaxStreamDataFrame) Length(version protocol.VersionNumber) protocol.ByteCount {
return 1 + quicvarint.VarIntLen(uint64(f.StreamID)) + quicvarint.VarIntLen(uint64(f.MaximumStreamData))
}