diff --git a/common/net/port.go b/common/net/port.go index 4da6baad..5882da05 100644 --- a/common/net/port.go +++ b/common/net/port.go @@ -39,11 +39,6 @@ func (p Port) Value() uint16 { return uint16(p) } -// Bytes returns the correspoding bytes of a Port, in big endian order. -func (p Port) Bytes(b []byte) []byte { - return serial.Uint16ToBytes(p.Value(), b) -} - // String returns the string presentation of a Port. func (p Port) String() string { return serial.Uint16ToString(p.Value()) diff --git a/common/protocol/address.go b/common/protocol/address.go index e1cfb3ae..70028469 100644 --- a/common/protocol/address.go +++ b/common/protocol/address.go @@ -7,6 +7,7 @@ import ( "v2ray.com/core/common/buf" "v2ray.com/core/common/net" "v2ray.com/core/common/task" + "v2ray.com/core/common/vio" ) type AddressOption func(*AddressParser) @@ -166,7 +167,7 @@ func (p *AddressParser) ReadAddressPort(buffer *buf.Buffer, input io.Reader) (ne } func (p *AddressParser) writePort(writer io.Writer, port net.Port) error { - return common.Error2(writer.Write(port.Bytes(nil))) + return common.Error2(vio.WriteUint16(writer, port.Value())) } func (p *AddressParser) writeAddress(writer io.Writer, address net.Address) error { diff --git a/proxy/vmess/encoding/commands.go b/proxy/vmess/encoding/commands.go index 11d93d67..f3e7ef65 100644 --- a/proxy/vmess/encoding/commands.go +++ b/proxy/vmess/encoding/commands.go @@ -9,6 +9,7 @@ import ( "v2ray.com/core/common/protocol" "v2ray.com/core/common/serial" "v2ray.com/core/common/uuid" + "v2ray.com/core/common/vio" ) var ( @@ -95,7 +96,7 @@ func (f *CommandSwitchAccountFactory) Marshal(command interface{}, writer io.Wri common.Must2(writer.Write([]byte(hostStr))) } - common.Must2(writer.Write(cmd.Port.Bytes(nil))) + common.Must2(vio.WriteUint16(writer, cmd.Port.Value())) idBytes := cmd.ID.Bytes() common.Must2(writer.Write(idBytes))