mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-04-30 01:29:09 -04:00
support packet transfer type in mux
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package serial
|
||||
|
||||
import "strconv"
|
||||
import "io"
|
||||
|
||||
// Uint16ToBytes serializes an uint16 into bytes in big endian order.
|
||||
func Uint16ToBytes(value uint16, b []byte) []byte {
|
||||
@@ -11,6 +12,14 @@ func Uint16ToString(value uint16) string {
|
||||
return strconv.Itoa(int(value))
|
||||
}
|
||||
|
||||
func ReadUint16(reader io.Reader) (uint16, error) {
|
||||
var b [2]byte
|
||||
if _, err := io.ReadFull(reader, b[:]); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return BytesToUint16(b[:]), nil
|
||||
}
|
||||
|
||||
func WriteUint16(value uint16) func([]byte) (int, error) {
|
||||
return func(b []byte) (int, error) {
|
||||
b = Uint16ToBytes(value, b[:0])
|
||||
|
||||
Reference in New Issue
Block a user