rename ReadVarint / WriteVarInt / VarIntLen to Read / Write / Len

This commit is contained in:
Marten Seemann
2021-01-01 11:40:53 +08:00
parent 11c5045065
commit f9226887b4
46 changed files with 298 additions and 298 deletions

View File

@@ -16,8 +16,8 @@ const (
maxVarInt8 = 4611686018427387903
)
// ReadVarInt reads a number in the QUIC varint format
func ReadVarInt(b io.ByteReader) (uint64, error) {
// Read reads a number in the QUIC varint format
func Read(b io.ByteReader) (uint64, error) {
firstByte, err := b.ReadByte()
if err != nil {
return 0, err
@@ -65,8 +65,8 @@ func ReadVarInt(b io.ByteReader) (uint64, error) {
return uint64(b8) + uint64(b7)<<8 + uint64(b6)<<16 + uint64(b5)<<24 + uint64(b4)<<32 + uint64(b3)<<40 + uint64(b2)<<48 + uint64(b1)<<56, nil
}
// WriteVarInt writes a number in the QUIC varint format
func WriteVarInt(b *bytes.Buffer, i uint64) {
// Write writes a number in the QUIC varint format
func Write(b *bytes.Buffer, i uint64) {
if i <= maxVarInt1 {
b.WriteByte(uint8(i))
} else if i <= maxVarInt2 {
@@ -83,14 +83,14 @@ func WriteVarInt(b *bytes.Buffer, i uint64) {
}
}
// WriteVarIntWithLen writes a number in the QUIC varint format, with the desired length.
func WriteVarIntWithLen(b *bytes.Buffer, i uint64, length protocol.ByteCount) {
// WriteWithLen writes a number in the QUIC varint format, with the desired length.
func WriteWithLen(b *bytes.Buffer, i uint64, length protocol.ByteCount) {
if length != 1 && length != 2 && length != 4 && length != 8 {
panic("invalid varint length")
}
l := VarIntLen(i)
l := Len(i)
if l == length {
WriteVarInt(b, i)
Write(b, i)
return
}
if l > length {
@@ -111,8 +111,8 @@ func WriteVarIntWithLen(b *bytes.Buffer, i uint64, length protocol.ByteCount) {
}
}
// VarIntLen determines the number of bytes that will be needed to write a number
func VarIntLen(i uint64) protocol.ByteCount {
// Len determines the number of bytes that will be needed to write a number
func Len(i uint64) protocol.ByteCount {
if i <= maxVarInt1 {
return 1
}