mirror of
https://github.com/daeuniverse/dae.git
synced 2025-07-21 05:09:55 +07:00
feat: add sniffing suite and dial_mode option (#16)
This commit is contained in:
25
component/sniffing/internal/quicutils/binary.go
Normal file
25
component/sniffing/internal/quicutils/binary.go
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright (c) since 2023, v2rayA Organization <team@v2raya.org>
|
||||
*/
|
||||
|
||||
package quicutils
|
||||
|
||||
import "io"
|
||||
|
||||
// BigEndianUvarint decodes a uint64 from buf and returns that value and the
|
||||
// number of bytes read (> 0).
|
||||
func BigEndianUvarint(buf []byte) (uint64, int, error) {
|
||||
if len(buf) == 0 {
|
||||
return 0, 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
length := 1 << (buf[0] >> 6)
|
||||
if length == 0 {
|
||||
return 0, 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
x := uint64(buf[0] & 0x3f)
|
||||
for i := 1; i < length; i++ {
|
||||
x = x<<8 | uint64(buf[i])
|
||||
}
|
||||
return x, length, nil
|
||||
}
|
Reference in New Issue
Block a user