forked from quic-go/quic-go
rename ReadVarint / WriteVarInt / VarIntLen to Read / Write / Len
This commit is contained in:
@@ -20,12 +20,12 @@ func parseCryptoFrame(r *bytes.Reader, _ protocol.VersionNumber) (*CryptoFrame,
|
||||
}
|
||||
|
||||
frame := &CryptoFrame{}
|
||||
offset, err := quicvarint.ReadVarInt(r)
|
||||
offset, err := quicvarint.Read(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
frame.Offset = protocol.ByteCount(offset)
|
||||
dataLen, err := quicvarint.ReadVarInt(r)
|
||||
dataLen, err := quicvarint.Read(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -44,27 +44,27 @@ func parseCryptoFrame(r *bytes.Reader, _ protocol.VersionNumber) (*CryptoFrame,
|
||||
|
||||
func (f *CryptoFrame) Write(b *bytes.Buffer, _ protocol.VersionNumber) error {
|
||||
b.WriteByte(0x6)
|
||||
quicvarint.WriteVarInt(b, uint64(f.Offset))
|
||||
quicvarint.WriteVarInt(b, uint64(len(f.Data)))
|
||||
quicvarint.Write(b, uint64(f.Offset))
|
||||
quicvarint.Write(b, uint64(len(f.Data)))
|
||||
b.Write(f.Data)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Length of a written frame
|
||||
func (f *CryptoFrame) Length(_ protocol.VersionNumber) protocol.ByteCount {
|
||||
return 1 + quicvarint.VarIntLen(uint64(f.Offset)) + quicvarint.VarIntLen(uint64(len(f.Data))) + protocol.ByteCount(len(f.Data))
|
||||
return 1 + quicvarint.Len(uint64(f.Offset)) + quicvarint.Len(uint64(len(f.Data))) + protocol.ByteCount(len(f.Data))
|
||||
}
|
||||
|
||||
// MaxDataLen returns the maximum data length
|
||||
func (f *CryptoFrame) MaxDataLen(maxSize protocol.ByteCount) protocol.ByteCount {
|
||||
// pretend that the data size will be 1 bytes
|
||||
// if it turns out that varint encoding the length will consume 2 bytes, we need to adjust the data length afterwards
|
||||
headerLen := 1 + quicvarint.VarIntLen(uint64(f.Offset)) + 1
|
||||
headerLen := 1 + quicvarint.Len(uint64(f.Offset)) + 1
|
||||
if headerLen > maxSize {
|
||||
return 0
|
||||
}
|
||||
maxDataLen := maxSize - headerLen
|
||||
if quicvarint.VarIntLen(uint64(maxDataLen)) != 1 {
|
||||
if quicvarint.Len(uint64(maxDataLen)) != 1 {
|
||||
maxDataLen--
|
||||
}
|
||||
return maxDataLen
|
||||
|
||||
Reference in New Issue
Block a user