move varint encoding / decoding to a separate package

... which is not internal.
This commit is contained in:
Marten Seemann 2021-01-01 11:37:19 +08:00
parent 602212e983
commit 11c5045065
47 changed files with 319 additions and 286 deletions

View file

@ -4,7 +4,7 @@ import (
"bytes"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/utils"
"github.com/lucas-clemente/quic-go/quicvarint"
)
// A MaxStreamDataFrame is a MAX_STREAM_DATA frame
@ -18,11 +18,11 @@ func parseMaxStreamDataFrame(r *bytes.Reader, _ protocol.VersionNumber) (*MaxStr
return nil, err
}
sid, err := utils.ReadVarInt(r)
sid, err := quicvarint.ReadVarInt(r)
if err != nil {
return nil, err
}
offset, err := utils.ReadVarInt(r)
offset, err := quicvarint.ReadVarInt(r)
if err != nil {
return nil, err
}
@ -35,12 +35,12 @@ func parseMaxStreamDataFrame(r *bytes.Reader, _ protocol.VersionNumber) (*MaxStr
func (f *MaxStreamDataFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error {
b.WriteByte(0x11)
utils.WriteVarInt(b, uint64(f.StreamID))
utils.WriteVarInt(b, uint64(f.MaximumStreamData))
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 + utils.VarIntLen(uint64(f.StreamID)) + utils.VarIntLen(uint64(f.MaximumStreamData))
return 1 + quicvarint.VarIntLen(uint64(f.StreamID)) + quicvarint.VarIntLen(uint64(f.MaximumStreamData))
}